package app;


import info.clearthought.layout.TableLayout;

import java.awt.Color;
import java.awt.Event;
import java.awt.Font;
import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.io.Writer;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.ProtocolException;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.swing.AbstractAction;
import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JEditorPane;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JProgressBar;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JSeparator;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.JTextPane;
import javax.swing.JToggleButton;
import javax.swing.KeyStroke;
import javax.swing.SwingUtilities;
import javax.swing.border.BevelBorder;
import javax.swing.border.LineBorder;
import javax.swing.border.SoftBevelBorder;
import javax.swing.event.UndoableEditEvent;
import javax.swing.event.UndoableEditListener;
import javax.swing.filechooser.FileNameExtensionFilter;
import javax.swing.text.BadLocationException;
import javax.swing.text.Caret;
import javax.swing.text.Document;
import javax.swing.undo.UndoManager;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;

import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import sun.font.StrikeCache;




 
/*
 * TODO
 *
 * obtener comunidades de un usuario
 * dir:http://www.taringa.net/perfil/USUARIO/comunidades
 * 
 * 
 * 
 * 
 */


/*
 * 0.85
 * Indicador de caracteres y limitado a 65000
 * Acortador de URLs
 * Notificador de nuevas versiones
 * Al reajustar el tamaño de la fuente el cursor vuelve a la posicion que estaba antes de la accion y no al principio
 * Autoguardado cada 5 minutos
 * Pequeñas correciones en la previsualizacion
 * 
 * 
 * 
 *
 *0.8
 *
 *Si no se configuro ningun navegador toma el navegador por defecto.
 *Posibilidad de eliminar los links debajo de los elementos multimedia
 *Soporte para Metacafe y DailyMotion
 *Posibilidad de añadir perfil dinamico
 *Detecta ftp como links
 *Se pueden añadir hasta 10 fuentes personalizadas
 *Pequeños arreglos a la previsualizacion
 *La funcion reemplazar todo funciona correctamente
 *
 *
 *
 * 0.76
 * Corregido :winky:
 * Se incorporo el boton de pantalla completa a los videos de youtbe
 * Pegado inteligente
 * 
 * 
 * 
 * 0.75
 * Posibilidad de añadir videos en alta definicion
 * Traductor de Google
 * Nuevo panel de preferencias
 * Los dialogos de insertar videos, links, comboImagenes, buscar se cierran al pulsar ESC
 * Se puede generar codigo automatico de una porcion del post
 * Agregado accesos directos de teclas para abrir borrador (ctrl-O) y guardar borrador (ctrl-S)
 * Los codigos predefinidos pueden almacenarse seleccionando una parte del texto
 * 
 * 
 * 0.71
 * Las comboImagenes en la previsualizacion mantienen su escala
 * Al pulsar ctrl-Y rehace las operaciones
 * 
 * 
 * 
 * 0.7
 * Mejorado cuadro de busqueda - Permite buscar/reemplazar/reemplazar todo
 * Solucionado bug que ponia a minusculas links de comboImagenes y videos que causaba que no se visualicen bien en algunos sitios
 * Estilos personalizados
 * Al posar el cursor del mouse sobre el boton de codigo predefinido se muestra el mismo
 * Mejorada la previsualizacion de comboImagenes
 * keystrokes para alinear ctrl-E, ctrl-R, ctrl-T, ctrl+up aumenta fuente, ctrl-down disminuye fuente
 * Pequeñas mejoras en la usabilidad
 * Mejorado el paquete .deb 
 * Teclas de acceso rapido a lso codigos predefinidos
 * 
 * 
 * 0.6
 * Posibilidad de agregar colores personalizados
 * Solucionado problema con acentos en la previsualizacion
 * Solucionado problema con perdida de foco al abrir un cuadro de dialogo
 * Soporte para https y no hace distincion entre mayusculas y minusculas
 * Busqueda sencilla
 * Posibilidad de guardar mas de un borrador y en formato de texto simple
 * Disponible en paquete .deb
 * La ventana conteniendo al codigo generado no se puede editar para evitar confusiones
 * 
 * 
 * Licencia GPL
 * http://www.gnu.org/licenses/gpl-3.0.txt
 * 
 * 
 */


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class Main extends javax.swing.JFrame  {

	{
		//Set Look & Feel
		
		
		try {
			javax.swing.UIManager.setLookAndFeel(javax.swing.UIManager.getSystemLookAndFeelClassName());
			
		} catch(Exception e) {
			e.printStackTrace();
		}
	}
	


	
	//Variables globales
	private AcercaDe acerca;
	String comentarios="";
	String comentariosComu="";
	String privado="";
	String follow="&follow=on";
	int indice=37;
	int indiceP=17;
	private String [] categorias = new String[indice];
	private int [] categoriasNum = new int[indice];
	
	private String [] categoriasP = new String[indiceP];
	private int [] categoriasNumP = new int[indiceP];
	
	
	String browser;
	String [] contenedor;
	String path;
	String title =null;
	Emoticones emos;
	private String version="1.42";
	String body =null;
	ArrayList<String> fuentesP = new ArrayList<String>();
	public boolean sigue=true;
	private boolean puedoPostear=true;
	private String borradorID="";
	final UndoManager undo = new UndoManager();
	Document doc;
	Fuente fuentes;
	private JTextField titulo;
	private JTextPane editor;
	private String propaganda="\n\n[align=left][img=http://dl.dropbox.com/u/155504/imagenes/postinga16z16.jpg][size=9][i]Post creado con PosT!NGA[/i][/size][/align]";
	private JButton dis_fuen;
	private JButton aum_fuen;
	private JMenuItem cortar;
	JMenu sub_fuente = new JMenu("Fuente");
	
	JMenu sub_tam = new JMenu("Tamaño");
	JMenu sub_color = new JMenu("Color");
	Font fuenteBoton=new java.awt.Font("Arial",0,12);
	JMenuItem sub_copiar = new JMenuItem("Copiar");
	JMenuItem sub_pegar = new JMenuItem("Pegar");
	private Borrador br;
	private	JMenuItem f9px = new JMenuItem("9px");
	private JMenuItem f12px = new JMenuItem("12px");
	private JMenuItem f14px = new JMenuItem("14px");
	private JMenuItem f16px = new JMenuItem("16px");
	private JMenuItem f18px = new JMenuItem("18px");
	private JMenuItem f20px = new JMenuItem("20px");
	private JMenuItem f22px = new JMenuItem("22px");
	private JMenuItem f24px = new JMenuItem("24px");
	final Esperar esp = new Esperar();
	private String fuentesDeInfo="";
	private String key="";
	private JMenuItem[] fuentesPersonales = new JMenuItem[10];	
	private JComboBox estilosComboBox;
	private JLabel estilosLabel;
	private JMenuItem configEstilos;
	private int caracteres;
	private JLabel jLabel6;
	private int autoTimer=5;
	private ButtonGroup selector = new ButtonGroup();
	public JComboBox comboImagenes;
	private JSeparator jSeparator5;
	private JMenuItem guardaBorrador;
	private JSeparator jSeparator4;
	private JMenuItem buscar;
	private JSeparator jSeparator3;
	private JMenuItem selAll;
	Timer timer2;	
	private JSeparator jSeparator2;
	private JMenuItem cut;
	private JMenuItem paste;
	private JMenuItem copy;
	private JMenuItem rehacer;
	private JMenuItem deshacer;
	Font arialBold12=new java.awt.Font("Arial",1,12);
	Font arialPlain12=new java.awt.Font("Arial",0,12);
	Font arialPlain10=new java.awt.Font("Arial",0,10);
	private JMenu edicion;
	private JButton bugs;
	private JButton preview;
	private JButton vimeo;
	private JButton plus_emo;
	private JButton emo1;
	private JButton emo16;
	private JButton emo15;
	private JButton emo14;
	private JButton emo13;
	private JButton emo12;
	private JButton emo11;
	private JButton emo10;
	private JButton emo9;
	private JButton emo8;
	private JButton emo7;
	private JButton emo6;
	private JButton emo5;
	private JButton emo4;
	private JButton emo3;
	private JPanel emoticons;
	private JButton emo2;
	JMenuItem rojo = new JMenuItem("Rojo");
	JMenuItem rojo_o = new JMenuItem("Rojo oscuro");
	JMenuItem marron = new JMenuItem("Marron");
	JMenuItem verde = new JMenuItem("Verde");
	JMenuItem naranja = new JMenuItem("Naranja");
	JMenuItem amarillo = new JMenuItem("Amarillo");
	JMenuItem oliva = new JMenuItem("Oliva");
	private JButton reloadComu;
	private JCheckBox sticky;
	private ButtonGroup comentariosGroup;
	private JCheckBox checkSoloRegistrados;
	private JRadioButton radioTodos;
	private JRadioButton radioNadie;
	private JRadioButton radioRangos;
	private JComboBox rangos;
	private JLabel indicador;
	private JCheckBox checkRecopilacion;
	private JRadioButton Cradio;
	private JRadioButton Pradio;
	private JRadioButton Tradio;
	private JButton btnFuentes;
	private JPanel postearEnPanel;
	private JMenuItem jMenuItem5;
	private JDropDownButton cargarBorrador;
	private JLabel chars;
	private JPanel jPanel3;
	private JSeparator jSeparator6;
	private JMenuItem ver;
	private JMenu Borradores;
	private JMenuItem nuevo;
	private OnOffButton prevOnline;
	private JLabel lblChars;
	private JProgressBar progressBar;
	private JLabel jLabel8;
	private JLabel jLabel7;
	private OnOffButton pegadoInt;
	private JPanel jPanel1;
	private JPanel opciones;
	private JTextField jTags;
	private JButton bPostear;
	private JLabel cat;
	private JComboBox comboCat;
	private JComboBox comboCatP;
	private JComboBox comboComu;
	private JMenuItem buscarAct;
	private JButton btnMetaCafe;
	private JButton btnDailyMotion;
	private JMenu ayuda;
	JMenuItem cyan = new JMenuItem("Cyan");
	JMenuItem azul = new JMenuItem("Azul");
	JMenuItem azul_o = new JMenuItem("Azul Oscuro");
	JMenuItem indigo = new JMenuItem("Indigo");
	JMenuItem violeta = new JMenuItem("Violeta");
	JMenuItem negro = new JMenuItem("Negro");
	JMenuItem customColor = new JMenuItem("Personalizado");
	
	private JButton bliptv;
	private JToggleButton borrar;
	private JToggleButton toggle;
	private JLabel jLabel2;
	private JButton cod4;
	private JButton cod3;
	private JButton cod2;
	private JButton cod1;
	private JSeparator jSeparator1;
	private JLabel jLabel1;
	private JPanel jPanel4;

	private ArrayList<String[]> listaImagenes;
	private ArrayList<String[]> listaEstilos;
	private ArrayList<String[]> listaComunidades; 
	Bbcode2html bbcode;
	
	
	private boolean pegadoInteligente=false;
	private int modo;
	/*
	 * modo 0: taringa
	 * modo 1: comunidades
	 * modo 2: poringa
	 * 
	 */
	
	JMenuItem [] arregloFuentes = new JMenuItem[10];
	
	JMenuItem arial = new JMenuItem("Arial");
	JMenuItem arial_b = new JMenuItem("Arial Black");
	JMenuItem american = new JMenuItem("American Typewriter");
	JMenuItem calibri = new JMenuItem("Calibri");
	JMenuItem century = new JMenuItem("Century");
	JMenuItem comic = new JMenuItem("Comic Sans MS");
	JMenuItem courier = new JMenuItem("Courier New");
	JMenuItem chiller = new JMenuItem("Chiller");
	JMenuItem fixed = new JMenuItem("FixedSys");
	JMenuItem french = new JMenuItem("French Script MT");
	JMenuItem georgia = new JMenuItem("Georgia");
	JMenuItem impact = new JMenuItem("Impact");
	JMenuItem lucida_c = new JMenuItem("Lucida Console");
	JMenuItem lucida_s = new JMenuItem("Lucida Sans");
	JMenuItem monotype = new JMenuItem("Monotype Corsiva");
	JMenuItem times = new JMenuItem("Times New Roman");
	JMenuItem tradicional = new JMenuItem("Traditional Arabic");
	JMenuItem trebuchet = new JMenuItem("Trebuchet MS");
	JMenuItem ubuntu = new JMenuItem("Ubuntu");
	JMenuItem verdana = new JMenuItem("Verdana");
	JMenuItem predef1,predef2,predef3,predef4,predef5,predef6,predef7,predef8,predef9,predef10;
	
	
	
	
	JPopupMenu popup1; 
	JMenuItem PopCortar1;
	JMenuItem PopPegar1;
	JMenuItem PopCopiar1;
	JMenuItem PopSelAll1;
	
	//Colores
	Color colorAzul = new Color(0,0,255);
	Color colorAzulO = new Color(0,45,184);
	Color colorVerde = new Color(0,255,0);
	Color colorRojo = new Color(255,0,0);
	Color colorRojoO = new Color(153,0,0);
	Color colorNaranja = new Color(255,102,51);
	Color colorVioleta = new Color(102,0,204);
	Color colorIndigo = new Color(115,0,153);
	Color colorCyan = new Color(102,255,255);
	Color colorMarron = new Color(156,26,0);
	Color colorNegro = new Color(0,0,0);
	Color colorOliva = new Color(153,153,0);
	Color colorAmarillo = new Color(255,231,15);
	Color colorBlanco = new Color(255,255,255);
	
	private JMenuItem selectall;
	private JMenuItem abrirB;
	private JDropDownButton later;
	private JSeparator separador;
	
	String ayudaPostinga="http://dl.dropbox.com/u/155504/ayudaPostinga.html";
	String bugsSite="http://taringa.net/comunidades/comunidadpostinga/1807153/Bugs.html";
	String lic = " This program is free software: you can redistribute it and/or modify \n  it under the terms of the GNU General Public License as published by \n  the Free Software Foundation, either version 3 of the License, or \n  (at your option) any later version. \n  \n This program is distributed in the hope that it will be useful,\n but WITHOUT ANY WARRANTY; without even the implied warranty of\n MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n GNU General Public License for more details.\n\n You should have received a copy of the GNU General Public License\n along with this program.  If not, see <http://www.gnu.org/licenses/>.\n";
	String autor = "\n\n PosT!NGA "+version+" compilacion: "+getCompilacion()+" \n hecho por Mukenio\n http://taringa.net/perfil/MukenioArg \n\n El logo de PosT!NGA es obra de JorgePastor66\n http://www.taringa.net/perfil/jorgepastor66 \n\n La funcionalidad para postear fue aportada por Abrahametalero\n http://www.taringa.net/perfil/abrahametalero";
	private JButton der;
	private JButton salir;
	private JButton gvideo;
	private JButton goear;
	private JButton swf;
	private JButton youtube;
	private JButton code;
	private JMenuItem jMenuItem2;
	private JMenuItem jMenuItem1;
	private JMenu jMenu1;
	private JMenuBar jMenuBar1;
	private JButton link;
	private JButton img;
	private JComboBox fonts;
	private JComboBox colores;
	private JButton center;
	private JButton izq;
	private JButton italica;
	private JPanel jPanel2;
	private JComboBox cmbTamaño;
	private JButton sub;
	private JScrollPane jScrollPane2;
	private JButton negrita;
	private JButton citar;
	private Dialog dialogo;
	private Code codigo;
	private Dialog2 dialogo2;
	private String challenge="";
	private JPopupMenu popup;
	private JButton imglnk;
	ConfigGUI config;
	ColorChooser colorCh;
	Buscar buscarDialog;
	String[] stringColores = new String[] { "Color","Rojo oscuro", "Rojo","Naranja","Marron","Amarillo","Verde","Oliva","Cyan","Azul","Azul oscuro","Indigo","Violeta","Negro","Personalizado" };
	String[] stringSizes= new String[] { "Tamaño", "9px","12px","14px","16px","18px","20px","22px","24px" };
	
	String[] stringFuentes =new String[] { "Fuente","American Typewriter","Arial","Arial Black","Calibri","Century","Chiller",  "Comic Sans","Courier New","FixedSys",
			"French Script MT", "Georgia","Impact", "Lucida Console","Lucida Sans","Monotype Corsiva",
				"Times New Roman", "Traditional Arabic","Trebuchet MS", "Ubuntu","Verdana"};
	
	ComboBoxModel fontsModel = new DefaultComboBoxModel(stringFuentes);
	private boolean rellenandoImgs=false;
	private boolean rellenandoEst=false;
	private static boolean primeraVez=false;
	private String icon_copy="copy.gif";
	private String icon_paste="paste.gif";
	private String icon_cut="cut.gif";
	private String icon_select_all="selectall.gif";
	private String icon_zoom_in="zoom_in_android.png";
	private String icon_zoom_out="zoom_out_android.png";
	private String tituloDefault="<<Ingresa el titulo del post aca>>";
	private String tagsDefault="<<Ingresa los tags del post aca>>";
	private Captcha cap;
	private ReportarBug bugReport;
	private String tituloVentana="PosT!NGA "+version;
	private ArrayList<String> fuentesInfo=new ArrayList<String>();
	//Tope de caracteres en el editor
	private int tope=63206;
	TimerTask timerTask = new TimerTask() 
    { 
        public void run()  
        { 
        	
				autoGuardarPost();
			
        	System.out.println("Autoguardado a las "+getDateTime() );
            Main.this.setTitle(tituloVentana+" - "+"Autoguardado a las "+getDateTime());
        } 
    }; 
    
    
    TimerTask timerTask2 = new TimerTask() 
    { 
        public void run()  
        { 
        	puedoPostear=true;
        } 
    }; 
	
    private String getDateTime() {
        DateFormat dateFormat = new SimpleDateFormat("HH:mm");
        Date date = new Date();
        return dateFormat.format(date);
    }
	
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				Main inst = new Main();
				inst.setLocationRelativeTo(null);
				/*JFrame.setDefaultLookAndFeelDecorated(true); //que nos permite dejar a Substance la decoracion ( por asi decirlo) 
					SubstanceLookAndFeel.setSkin("org.jvnet.substance.skin.BusinessBlueSteelSkin"); // Setencia que aplica el skin Creme de Substance
				SubstanceLookAndFeel.setCurrentTheme("org.jvnet.substance.theme.SubstanceCremeTheme");
				*/
				inst.setVisible(true);
				if (primeraVez) inst.toBack();
				
			}
		});
	}
	CookiesInJava cook = new CookiesInJava();
	
	
	
	public String getCompilacion() {
		String mes="";
		Calendar cal = Calendar.getInstance();
		int iDay=cal.get(Calendar.DATE);
        int iMonth=cal.get(Calendar.MONTH)+1; 
        int iYear=cal.get(Calendar.YEAR);
        if (iMonth<10) mes='0'+Integer.toString(iMonth);
        else Integer.toString(iMonth);
		return Integer.toString(iYear)+mes+Integer.toString(iDay);
	}
	
	
	
	
	public Main() {
		super();
		config = new ConfigGUI(this,cook);
		
		initCategorias();
		initCategoriasP();
		initGUI();
		fuentes = new Fuente(this);
		editor.requestFocus();
		dialogo = new Dialog(null);
		dialogo.conectar(this);
		dialogo.setLocationRelativeTo(null);
		dialogo.setLinkEnabled(true);
		dialogo2 = new Dialog2(null);
		dialogo2.conectar(this);
		dialogo2.setLocationRelativeTo(null);
		path=config.getPath();
		
		
		bbcode = new Bbcode2html();
		
		rellenarImagenes();
		rellenarEstilos();
		rellenarComunidades();
		cargarTooltips();
		setFuentesPopup();
		pegadoInt.setSelected(config.getActivarInicioPI());
		pegadoInteligente=config.getActivarInicioPI();
		if (pegadoInteligente) sub_pegar.setText("Pegado Inteligente");
		
		CrearFuentesPopUp();
		insertarFuentes();
		if (!config.existeConfig()) {
			try {
				
				JOptionPane.showMessageDialog( this,"Parece que es la primera vez que inicias PosT!NGA\n\nConfigurá tu cuenta y el navegador primero",    "Bienvenido!", JOptionPane.PLAIN_MESSAGE );
				config.setLocationRelativeTo(null);
				config.guardarConfig();
				config.setVisible(true);
				primeraVez=true;
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
			
		}
		if (config.checkUpdate()) checkUpdates(true);
		autoGuardar();
		
		
	}
	
	
	private void autoGuardar() {
 
		Timer timer = new Timer();		//crear el timer 
		 timer.scheduleAtFixedRate(timerTask,60000*1,60000*autoTimer); //Cada 5 minutos se ejecuta la tarea
	}
	
	private void setFuentesPopup() {
		
		arial.setFont(new java.awt.Font("Ubuntu",0,12));
		arial_b.setFont(new java.awt.Font("Ubuntu",0,12));
		american.setFont(new java.awt.Font("Ubuntu",0,12));
		calibri.setFont(new java.awt.Font("Ubuntu",0,12));
		century.setFont(new java.awt.Font("Ubuntu",0,12));
		comic.setFont(new java.awt.Font("Ubuntu",0,12));
		courier.setFont(new java.awt.Font("Ubuntu",0,12));
		chiller.setFont(new java.awt.Font("Ubuntu",0,12));
		fixed.setFont(new java.awt.Font("Ubuntu",0,12));
		french.setFont(new java.awt.Font("Ubuntu",0,12));
		georgia.setFont(new java.awt.Font("Ubuntu",0,12));
		impact.setFont(new java.awt.Font("Ubuntu",0,12));
		lucida_c.setFont(new java.awt.Font("Ubuntu",0,12));
		lucida_s.setFont(new java.awt.Font("Ubuntu",0,12));
		monotype.setFont(new java.awt.Font("Ubuntu",0,12));
		times.setFont(new java.awt.Font("Ubuntu",0,12));
		tradicional.setFont(new java.awt.Font("Ubuntu",0,12));
		trebuchet.setFont(new java.awt.Font("Ubuntu",0,12));
		ubuntu.setFont(new java.awt.Font("Ubuntu",0,12));
		verdana.setFont(new java.awt.Font("Ubuntu",0,12));
		
		rojo.setFont(new java.awt.Font("Ubuntu",0,12));
		rojo_o.setFont(new java.awt.Font("Ubuntu",0,12));
		marron.setFont(new java.awt.Font("Ubuntu",0,12));
		verde.setFont(new java.awt.Font("Ubuntu",0,12));
		impact.setFont(new java.awt.Font("Ubuntu",0,12));
		naranja.setFont(new java.awt.Font("Ubuntu",0,12));
		amarillo.setFont(new java.awt.Font("Ubuntu",0,12));
		oliva.setFont(new java.awt.Font("Ubuntu",0,12));
		cyan.setFont(new java.awt.Font("Ubuntu",0,12));
		azul.setFont(new java.awt.Font("Ubuntu",0,12));
		azul_o.setFont(new java.awt.Font("Ubuntu",0,12));
		indigo.setFont(new java.awt.Font("Ubuntu",0,12));
		violeta.setFont(new java.awt.Font("Ubuntu",0,12));
		negro.setFont(new java.awt.Font("Ubuntu",0,12));
		customColor.setFont(new java.awt.Font("Ubuntu",0,12));
		
		f9px.setFont(new java.awt.Font("Ubuntu",0,12));
		f12px.setFont(new java.awt.Font("Ubuntu",0,12));
		f14px.setFont(new java.awt.Font("Ubuntu",0,12));
		f16px.setFont(new java.awt.Font("Ubuntu",0,12));
		f18px.setFont(new java.awt.Font("Ubuntu",0,12));
		f20px.setFont(new java.awt.Font("Ubuntu",0,12));
		f22px.setFont(new java.awt.Font("Ubuntu",0,12));
		f24px.setFont(new java.awt.Font("Ubuntu",0,12));
		
		
	}
	
	
	private void cargarTooltips() {
	
	cod1.setToolTipText("<html>"+bbcode.convertir(config.cargarCod(1))+"</html>");
	cod2.setToolTipText("<html>"+bbcode.convertir(config.cargarCod(2))+"</html>");
	cod3.setToolTipText("<html>"+bbcode.convertir(config.cargarCod(3))+"</html>");
	cod4.setToolTipText("<html>"+bbcode.convertir(config.cargarCod(4))+"</html>");
	}
	
	private void initCategorias() {
		
		
		
		
		
		categorias[0]="";categoriasNum[0]=-1;
		categorias[1]="Animaciones"; categoriasNum[1]=7;
		categorias[2]="Apuntes y monografias"; categoriasNum[2]=18;
		categorias[3]="Arte"; categoriasNum[3]=4;
		categorias[4]="Autos y motos"; categoriasNum[4]=25;
		categorias[5]="Celulares"; categoriasNum[5]=17;
		categorias[6]="Ciencia y educación"; categoriasNum[6]=33;
		categorias[7]="Comics e historietas";categoriasNum[7]=19;
		categorias[8]="Deportes";categoriasNum[8]=16;
		categorias[9]="Downloads";categoriasNum[9]=9;
		categorias[10]="E-books y Tutoriales";categoriasNum[10]=23;
		categorias[11]="Ecologia";categoriasNum[11]=34;
		categorias[12]="Economia y Negocios";categoriasNum[12]=29;
		categorias[13]="Femme";categoriasNum[13]=24;
		categorias[14]="Hazlo tu mismo";categoriasNum[14]=35;
		categorias[15]="Humor";categoriasNum[15]=26;
		categorias[16]="Imagenes";categoriasNum[16]=1;
		categorias[17]="Info";categoriasNum[17]=12;
		categorias[18]="Juegos";categoriasNum[18]=0;
		categorias[19]="Juegos On-line";categoriasNum[19]=38;
		categorias[20]="Links";categoriasNum[20]=2;
		categorias[21]="Linux y GNU";categoriasNum[21]=15;
		categorias[22]="Mac";categoriasNum[22]=22;
		categorias[23]="Manga y anime";categoriasNum[23]=32;
		categorias[24]="Mascotas";categoriasNum[24]=30;
		categorias[25]="Musica";categoriasNum[25]=8;
		categorias[26]="Noticias";categoriasNum[26]=10;
		categorias[27]="Off-topic";categoriasNum[27]=5;
		categorias[28]="Paranormal";categoriasNum[28]=36;
		categorias[29]="Recetas y Cocina ";categoriasNum[29]=21;
		categorias[30]="Reviews";categoriasNum[30]=37;
		categorias[31]="Salud y Bienestar";categoriasNum[31]=27;
		categorias[32]="Solidaridad";categoriasNum[32]=20;
		categorias[33]="Taringa!";categoriasNum[33]=28;
		categorias[34]="Turismo";categoriasNum[34]=31;
		categorias[35]="TV, Peliculas y Series";categoriasNum[35]=13;
		categorias[36]="Videos On-line";categoriasNum[36]=3;
		
}
   
	private void initCategoriasP() {
		categoriasP[0]="";categoriasNum[0]=-1;
		categoriasP[1]="Animaciones"; categoriasNumP[1]=7;
		categoriasP[2]="Downloads"; categoriasNumP[2]=9;
		categoriasP[3]="Gay"; categoriasNumP[3]=8;
		categoriasP[4]="Hentai"; categoriasNumP[4]=15;
		categoriasP[5]="Imagenes"; categoriasNumP[5]=1;
		categoriasP[6]="Info"; categoriasNumP[6]=12;
		categoriasP[7]="Links";categoriasNumP[7]=2;
		categoriasP[8]="No apto";categoriasNumP[8]=6;
		categoriasP[9]="Noticias";categoriasNumP[9]=10;
		categoriasP[10]="Novatos";categoriasNumP[10]=11;
		categoriasP[11]="Off-topic";categoriasNumP[11]=5;
		categoriasP[12]="Patrocinados";categoriasNumP[12]=14;
		categoriasP[13]="Poringueras";categoriasNumP[13]=4;
		categoriasP[14]="Relatos";categoriasNumP[14]=0;
		categoriasP[15]="Tv Peliculas y Series";categoriasNumP[15]=13;
		categoriasP[16]="Videos On-line";categoriasNumP[16]=3;
		
		
}
	
	
	 public void rellenarEstilos() {
			rellenandoEst=true;
		 	listaEstilos=(ArrayList<String[]>) config.getEstilos().clone();
			if (config.getEstilos()!=null) {
			estilosComboBox.removeAllItems();
			estilosComboBox.addItem(""); //el primer item es vacio
			for (int i=0; i<config.getEstilos().size();i++) estilosComboBox.addItem(config.getEstilos().get(i)[0]);
		}
			
			
			rellenandoEst=false;
		}
	
	
	public void rellenarImagenes() {
		rellenandoImgs=true;
		listaImagenes=(ArrayList<String[]>) config.getImagenes().clone();
		if (listaImagenes!=null) {
		comboImagenes.removeAllItems();
		comboImagenes.addItem(""); //el primer item es vacio
		for (int i=0; i<listaImagenes.size();i++) comboImagenes.addItem(listaImagenes.get(i)[0]);
	}
			
		rellenandoImgs=false;
	
	}
	public void rellenarComunidades() {
		
		listaComunidades=(ArrayList<String[]>) config.getComunidades().clone();
		if (listaComunidades!=null) {
		comboComu.removeAllItems();
		comboComu.addItem(""); //el primer item es vacio
		for (int i=0; i<listaComunidades.size();i++) {
			comboComu.addItem(listaComunidades.get(i)[1]);
			
	
		}
		}
		
	
	}
	
	public int getIndexComboComu(String comunidad) {
		int resultado=-1;
		String [] temp;
		for (int i=0;i<listaComunidades.size();i++)
		{
			temp=listaComunidades.get(i);
			if (temp[0].equals(comunidad)) return i;
		}
		return resultado;
		
	}
	
	
	
	
	private void initGUI() {
		try {	
			
			
			
			TableLayout thisLayout = new TableLayout(new double[][] {{7.0, TableLayout.FILL, TableLayout.FILL, TableLayout.FILL, TableLayout.FILL, 7.0}, {30.0, 112.0, TableLayout.MINIMUM, TableLayout.MINIMUM, TableLayout.FILL, 43.0, 160.0}});
			thisLayout.setHGap(5);
			thisLayout.setVGap(5);
			getContentPane().setLayout(thisLayout);
			
			setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); 
			this.addWindowListener(new WindowAdapter() {
		          public void windowClosing(WindowEvent e) {
           salir();
		          }
		      });
			//getContentPane().setBackground(new java.awt.Color(216,216,216));
			this.setTitle(tituloVentana);
			this.setIconImage(new ImageIcon(getClass().getClassLoader().getResource("app/postinga16x16.png")).getImage());
			
			
			{
				jMenuBar1 = new JMenuBar();
				setJMenuBar(jMenuBar1);
				//jMenuBar1.setBackground(new java.awt.Color(255,255,255));
				jMenuBar1.add(getJMenu1());
				jMenuBar1.add(getEdicion());
				jMenuBar1.add(getBorradores());
				jMenuBar1.add(getAyuda());
			}
			getContentPane().add(getTitulo(), "2,0,3,0,c,c");
			getContentPane().add(getJScrollPane2(), "1, 2, 4, 4");
			if (config.checkNumerosLineas()) {
				TextLineNumber tln = new TextLineNumber(editor);
				getJScrollPane2().setRowHeaderView( tln );
			}
			
			getContentPane().add(getJPanel2(), "1, 1, 4, 1");
			
			getContentPane().add(getEmoticons(), "1,5,4,5,f,f");
			getContentPane().add(getBugs(), "4, 0, c, f");
			getContentPane().add(getOpciones(), "2,6,3,6,f,c");
			getContentPane().add(getJPanel1(), "4, 6");
			getContentPane().add(getJPanel3(), "1, 6");
			getContentPane().add(getJPanel5(), "1, 0");
			
			
			/// prox version
			
			postearEnPanel.setVisible(true);
			
			
			
			getPopup();
			getPopup1();
			pack();
			modoPostT();
			
			this.setSize(835, 707);
		} catch (Exception e) {
		    //add your error handling code here
			e.printStackTrace();
		}
	}
	
	
	
	public String[] getStringFuentes(){
		return stringFuentes;
	}
	
	public String [] getStringColores() {
		return stringColores;
		}
	
	
	public String [] getStringSizes() {
		
		return stringSizes;
	}
	
	
	
	
	private JTextField getTitulo() {
		if(titulo == null) {
			titulo = new JTextField();
			titulo.setName("titulo");
			titulo.setPreferredSize(new java.awt.Dimension(501, 259));
			titulo.setOpaque(false);
			initTitulo();

			titulo.addFocusListener(new FocusAdapter() {
				public void focusLost(FocusEvent evt) {
					tituloFocusLost(evt);
				}
				public void focusGained(FocusEvent evt) {
					tituloFocusGained(evt);
				}
			});
		}
		return titulo;
	}
	
	private JEditorPane getEditor() {
		if(editor == null) {
			editor = new JTextPane();
			
			editor.setBorder(BorderFactory.createTitledBorder(""));
			editor.setDragEnabled(true);
			editor.setPreferredSize(new java.awt.Dimension(1201, 381));
			editor.setBackground(new java.awt.Color(255,255,255));
			editor.addKeyListener(new KeyAdapter() {
				public void keyReleased(KeyEvent evt) {
					editorKeyReleased(evt);
				}
			});

			editor.setFont(new java.awt.Font("Arial",0,13));
			
			doc = editor.getDocument();
			doc.addUndoableEditListener(new UndoableEditListener() {
		        public void undoableEditHappened(UndoableEditEvent evt) {
		            undo.addEdit(evt.getEdit());
		        }
		    });

		    // Create an undo action and add it to the text component
		    editor.getActionMap().put("Undo",
		        new AbstractAction("Undo") {
		            /**
					 * 
					 */
					private static final long serialVersionUID = 1L;

					public void actionPerformed(ActionEvent evt) {
		                try {
		                    if (undo.canUndo()) {
		                        undo.undo();
		                    }
		                } catch (Exception e) {
		                }
		            }
		       });

		    // Bind the undo action to ctl-Z
		    editor.getInputMap().put(KeyStroke.getKeyStroke("control Z"), "Undo");
		    

		    // Create a redo action and add it to the text component
		    editor.getActionMap().put("Redo",
		        new AbstractAction("Redo") {
		            public void actionPerformed(ActionEvent evt) {
		                try {
		                    if (undo.canRedo()) {
		                        undo.redo();
		                    }
		                } catch (Exception e) {
		                }
		            }
		        });
		    editor.getInputMap().put(KeyStroke.getKeyStroke("control Y"), "Redo");
		    
		    editor.getActionMap().put("Paste",
			        new AbstractAction("Paste") {
			            public void actionPerformed(ActionEvent evt) {
			                try {
			                   
			                       pegadoInteligente();
			                    
			                } catch (Exception e) {
			                }
			            }
			        });
			    editor.getInputMap().put(KeyStroke.getKeyStroke("control V"), "Paste");
		    

			
			
		}
		return editor;
	}
	

	
	private void pegadoInteligente() {
		if (pegadoInteligente) editor.replaceSelection(Analizador.convierte(getClipboardContents(),config.getCentrarImagenesPI(),config.getIncluirLinksPI(),true,config.getPegadoIntel()[3]));
		else
			editor.replaceSelection(getClipboardContents());
	}
	
	


	private JScrollPane getJScrollPane2() {
		if(jScrollPane2 == null) {
			jScrollPane2 = new JScrollPane();
			jScrollPane2.setViewportView(getEditor());
		}
		
		return jScrollPane2;
	}

	private void citarMouseClicked(MouseEvent evt) {
		
		
		String seleccion=editor.getSelectedText();
		if (!(dialogo.isVisible() | (dialogo2.isVisible()))) {
			if (seleccion != null) 
				generarQuote(seleccion);
		else
		{	
			dialogo.setTipo("quote");
			dialogo.setLinkEnabled(false);
			dialogo.cambiarLabel("Ingresa el texto a citar");
			dialogo.setTitle("Insertar quote");
		
		dialogo.setVisible(true);
		
		
		}
			dialogo.obtenerFoco();

		
	}
		
	}
	
	private JButton getNegrita() {
		if(negrita == null) {
			negrita = new JButton();
			negrita.setIcon(new ImageIcon(getClass().getResource("bold.gif")));
			negrita.setBackground(new java.awt.Color(255,255,255));
			negrita.setSize(30, 30);
			negrita.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_B, Event.CTRL_MASK), "play");
			negrita.getActionMap().put("play", new AbstractAction() {
			/**
				 * 
				 */
				private static final long serialVersionUID = 1L;

			public void actionPerformed(ActionEvent e) {
			 aplicar_negrita();  // some function
			}
			});
			negrita.setPreferredSize(new java.awt.Dimension(30, 30));
			negrita.setToolTipText("Negrita (Ctrl-B)");
			negrita.setBorderPainted(false);
			negrita.addMouseListener(new MouseAdapter() {
				public void mouseClicked(MouseEvent evt) {
					negritaMouseClicked(evt);
				}
			});
		}
		return negrita;
	}
	
	private JButton getCitar() {
		if(citar == null) {
			citar = new JButton();
			citar.setIcon(new ImageIcon(getClass().getResource("quote.png")));
			citar.setPreferredSize(new java.awt.Dimension(30, 30));
			citar.setSize(30, 30);
			citar.setBorderPainted(false);
			citar.setToolTipText("Citar");
			citar.addMouseListener(new MouseAdapter() {
				public void mouseClicked(MouseEvent evt) {
					citarMouseClicked(evt);
				}
			});
		}
		return citar;
	}
	
	
	private JButton getItalica() {
		if(italica == null) {
			italica = new JButton();
			italica.setIcon(new ImageIcon(getClass().getResource("italic.gif")));
			
			italica.setBackground(new java.awt.Color(255,255,255));
			italica.setPreferredSize(new java.awt.Dimension(30, 30));
			italica.setSize(30, 30);
			italica.setToolTipText("Italica (Ctrl-I)");
			italica.setBorderPainted(false);
			italica.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_I, Event.CTRL_MASK), "play");
			italica.getActionMap().put("play", new AbstractAction() {
			/**
				 * 
				 */
				private static final long serialVersionUID = 1L;

			public void actionPerformed(ActionEvent e) {
			 aplicar_italica();  // some function
			}
			});
			italica.addMouseListener(new MouseAdapter() {
				public void mouseClicked(MouseEvent evt) {
					italicaMouseClicked(evt);
				}
			});
		}
		return italica;
	}
	
	
	private JButton getSub() {
		if(sub == null) {
			sub = new JButton();
			sub.setIcon(new ImageIcon(getClass().getResource("underline.gif")));
			sub.setBackground(new java.awt.Color(255,255,255));
			sub.setPreferredSize(new java.awt.Dimension(30, 30));
			sub.setSize(30, 30);
			sub.setOpaque(false);
			sub.setToolTipText("Subrayado Ctrl-U");
			sub.setBorderPainted(false);
			sub.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_U, Event.CTRL_MASK), "play");
			sub.getActionMap().put("play", new AbstractAction() {
			/**
				 * 
				 */
				private static final long serialVersionUID = 1L;

			public void actionPerformed(ActionEvent e) {
			 aplicar_sub();  // some function
			}
			});
			sub.addMouseListener(new MouseAdapter() {
				public void mouseClicked(MouseEvent evt) {
					subMouseClicked(evt);
				}
			});
		}
		return sub;
	}
	
	private JButton getIzq() {
		if(izq == null) {
			izq = new JButton();
			
			izq.setIcon(new ImageIcon(getClass().getResource("left2.gif")));
			izq.setBackground(new java.awt.Color(255,255,255));
			izq.setPreferredSize(new java.awt.Dimension(28, 28));
			izq.setSize(28, 28);
			izq.setBorderPainted(false);
			izq.setToolTipText("Alinear a izquierda (Ctrl-E)");
			izq.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_E, Event.CTRL_MASK), "play");
    		izq.getActionMap().put("play", new AbstractAction() {
			private static final long serialVersionUID = 1L;
			public void actionPerformed(ActionEvent e) {
				alinearIzq();  // some function
			}
			});
			
			
			izq.addMouseListener(new MouseAdapter() {
				public void mouseClicked(MouseEvent evt) {
					izqMouseClicked(evt);
				}
			});
		}		return izq;
	}
	
	private JButton getCenter() {
		if(center == null) {
			center = new JButton();
			center.setIcon(new ImageIcon(getClass().getResource("center2.gif")));
			center.setBackground(new java.awt.Color(255,255,255));
			center.setPreferredSize(new java.awt.Dimension(28,28));
			center.setSize(28, 28);
			center.setBorderPainted(false);
			center.setToolTipText("Centrar (Ctrl-R)");
			center.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_R, Event.CTRL_MASK), "play");
			center.getActionMap().put("play", new AbstractAction() {
			/**
				 * 
				 */
				private static final long serialVersionUID = 1L;

			public void actionPerformed(ActionEvent e) {
				alinearCentro();  // some function
			}
			});
			center.addMouseListener(new MouseAdapter() {
				public void mouseClicked(MouseEvent evt) {
					centerMouseClicked(evt);
				}
			});
		}
		return center;
	}
	
	private JButton getDer() {
		if(der == null) {
			der = new JButton();
			der.setIcon(new ImageIcon(getClass().getResource("right2.gif")));
			der.setBackground(new java.awt.Color(255,255,255));
			der.setPreferredSize(new java.awt.Dimension(28, 28));
			der.setSize(28, 28);
			der.setBorderPainted(false);
			der.setToolTipText("Alinear a derecha (Ctrl-R)");
			der.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_T, Event.CTRL_MASK), "play");
			der.getActionMap().put("play", new AbstractAction() {
			/**
				 * 
				 */
				private static final long serialVersionUID = 1L;

			public void actionPerformed(ActionEvent e) {
				alinearDerecha();  // some function
			}
			});
			der.addMouseListener(new MouseAdapter() {
				public void mouseClicked(MouseEvent evt) {
					derMouseClicked(evt);
				}
			});
		}
		return der;
	}
	

	
	
	
	private JButton getImg() {
		if(img == null) {
			img = new JButton();
			img.setIcon(new ImageIcon(this.getClass().getResource("imagen.png")));
			img.setPreferredSize(new java.awt.Dimension(30, 30));
			img.setSize(30, 30);
			img.setBorderPainted(false);
			img.setToolTipText("Insertar Imagen");
			img.addMouseListener(new MouseAdapter() {
				public void mouseClicked(MouseEvent evt) {
					imgMouseClicked(evt);
				}
			});
		}
		return img;
	}
	
	private JButton getLink() {
		if(link == null) {
			link = new JButton();
			link.setIcon(new ImageIcon(getClass().getResource("link.gif")));
			link.setPreferredSize(new java.awt.Dimension(30, 30));
			link.setSize(30, 30);
			link.setBorderPainted(false);
			link.setToolTipText("Insertar Link");
			link.addMouseListener(new MouseAdapter() {
				public void mouseClicked(MouseEvent evt) {
					linkMouseClicked(evt);
				}
			});
		}
		return link;
	}
	
	private JButton getImglnk() {
		if(imglnk == null) {
			imglnk = new JButton();
			imglnk.setIcon(new ImageIcon(getClass().getResource("img_link.png")));
			imglnk.setBorderPainted(false);
			imglnk.setPreferredSize(new java.awt.Dimension(30, 30));
			imglnk.setSize(30, 30);
			imglnk.setToolTipText("Insertar Imagen con link");}
		imglnk.addMouseListener(new MouseAdapter() {
			public void mouseClicked(MouseEvent evt) {
				imglnkMouseClicked(evt);
			}
		});
		return imglnk;
	}
	
	
	private JButton getCode() {
		if(code == null) {
			code = new JButton();
			code.setPreferredSize(new java.awt.Dimension(30, 30));
			code.setSize(30, 30);
			code.setIcon(new ImageIcon(getClass().getResource("code.jpg")));
			code.setToolTipText("[Code]");
			code.setBorderPainted(false);
			code.addMouseListener(new MouseAdapter() {
				public void mouseClicked(MouseEvent evt) {
					codeMouseClicked(evt);
				}
			});
		}
		return code;
	}
	
	private JButton getYoutube() {
		if(youtube == null) {
			youtube = new JButton();
			youtube.setIcon(new ImageIcon(getClass().getResource("youtube.png")));
			youtube.setBorderPainted(false);
			youtube.setPreferredSize(new java.awt.Dimension(30, 30));
			youtube.setSize(30, 30);
			youtube.setToolTipText("Insertar Video de Youtube");
			youtube.addMouseListener(new MouseAdapter() {
				public void mouseClicked(MouseEvent evt) {
					youtubeMouseClicked(evt);
				}
			});

		}
		return youtube;
	}
	
	private JButton getSwf() {
		if(swf == null) {
			swf = new JButton();
			swf.setIcon(new ImageIcon(getClass().getResource("swf.gif")));
			swf.setPreferredSize(new java.awt.Dimension(30, 30));
			swf.setSize(30, 30);
			swf.setBorderPainted(false);
			swf.setToolTipText("Insertar SWF");
			swf.addMouseListener(new MouseAdapter() {
				public void mouseClicked(MouseEvent evt) {
					swfMouseClicked(evt);
				}
			});

		}
		return swf;
	}
	private JButton getGoear() {
		if(goear == null) {
			goear = new JButton();
			goear.setPreferredSize(new java.awt.Dimension(30, 30));
			goear.setSize(30, 30);
			goear.setBorderPainted(false);
			goear.setIcon(new ImageIcon(getClass().getResource("goear.png")));
			goear.setToolTipText("Insertar cancion de GoEar");
			goear.addMouseListener(new MouseAdapter() {
				public void mouseClicked(MouseEvent evt) {
					goearMouseClicked(evt);
				}
			});
		}		return goear;
	}

	private JButton getGvideo() {
		if(gvideo == null) {
			gvideo = new JButton();
			gvideo.setPreferredSize(new java.awt.Dimension(30, 30));
			gvideo.setSize(30, 30);
			gvideo.setBorderPainted(false);
			gvideo.setIcon(new ImageIcon(getClass().getResource("google.png")));
			gvideo.setToolTipText("Insertar Video de Google Video");
			gvideo.addMouseListener(new MouseAdapter() {
				public void mouseClicked(MouseEvent evt) {
					gvideoMouseClicked(evt);
				}
			});
		}
		return gvideo;
	}
	
	
	
	
	
	
	
	
	
		
	
	private JPanel getJPanel2() {
		if(jPanel2 == null) {
			jPanel2 = new JPanel();
			TableLayout jPanel2Layout = new TableLayout(new double[][] {{7.0, TableLayout.FILL, TableLayout.FILL, TableLayout.FILL, 7.0, TableLayout.FILL, 7.0, TableLayout.FILL, 32.0, TableLayout.FILL, TableLayout.FILL}, {7.0, TableLayout.FILL, TableLayout.FILL, TableLayout.FILL, 7.0}});
			jPanel2Layout.setHGap(5);
			jPanel2Layout.setVGap(5);
			jPanel2.setLayout(jPanel2Layout);
			//jPanel2.setBackground(new java.awt.Color(255,255,255));
			jPanel2.setBorder(new LineBorder(new java.awt.Color(0,0,0), 1, false));
			jPanel2.add(getCitar(), "5, 2, r, f");
			jPanel2.add(getCmbTamaño(), "7,1,f,c");
			jPanel2.add(getNegrita(), "3, 2, c, c");
			jPanel2.add(getSub(), "3, 2, r, c");
			jPanel2.add(getItalica(), "3, 2, l, c");
			jPanel2.add(getIzq(), "3, 3, l, f");
			jPanel2.add(getCenter(), "3, 3, c, f");
			jPanel2.add(getDer(), "3, 3, r, f");
			jPanel2.add(getcolores(), "5,1,f,c");
			jPanel2.add(getFonts(), "3,1,f,c");
			jPanel2.add(getImg(), "5, 2, c, f");
			jPanel2.add(getLink(), "5, 2, l, f");
			jPanel2.add(getYoutube(), "5, 3, r, f");
			jPanel2.add(getCode(), "5, 3, c, f");
			jPanel2.add(getSwf(), "5, 3, l, f");
			jPanel2.add(getGoear(), "7, 3, l, f");
			jPanel2.add(getGvideo(), "7, 3, r, f");
			jPanel2.add(getImglnk(), "7,2,l,f");
			jPanel2.add(getJPanel4(), "9, 1, 10, 3");
			jPanel2.add(getCod1(), "2,2,l,f");
			jPanel2.add(getCod2(), "2,2,c,f");
			jPanel2.add(getCod3(), "2,3,l,f");
			jPanel2.add(getCod4(), "2,3,c,f");
			jPanel2.add(getJLabel2(), "1,1,2,1,c,f");
			jPanel2.add(getToggle(), "1,2,c,f");
			jPanel2.add(getBorrar(), "1,3,c,f");
			jPanel2.add(getBliptv(), "7,2,c,f");
			jPanel2.add(getVimeo(), "7,2,r,f");
			jPanel2.add(getJButton2(), "7, 3");
			jPanel2.add(getJButton3(), "8, 3");
		}
		return jPanel2;
	}
	
	
	private void codeMouseClicked(MouseEvent evt) {
		String seleccion=editor.getSelectedText();
		if (seleccion == null) {
			if (codigo==null) {
				codigo = new Code(null);
				codigo.conectar(this);
			}
			codigo.setLocationRelativeTo(this);
			codigo.setVisible(true);
			codigo.obtenerFoco();
		}
		
		else
			editor.replaceSelection("[code]"+seleccion+"[/code]");
		editor.requestFocus();
	}
	
	


public String seleccion(){
	return editor.getSelectedText();
}
	
	
public void generarLink(String link,String texto) {
		
		editor.replaceSelection(Analizador.agregarLink(link,texto));		
	}

public void generarCode(String str) {
	
	editor.replaceSelection("[code]"+str+"[/code]");
	
}

public void generarQuote(String str){
	editor.replaceSelection(Analizador.agregarQuote(str));
}



public void generarImagenConLink(String link,String imagen,boolean centrado) {
	
	editor.replaceSelection(Analizador.agregarImagenConLink(link,imagen,centrado));
	
}
	public void generarYoutube(String str,boolean hd,boolean link) {
		
		editor.replaceSelection(Analizador.agregarVideo(str,hd,link));
		
	}
	
	public void generarGoear(String str,boolean link) {
		
		editor.replaceSelection(Analizador.agregarGoear(str,link));
		
	}
	

public void generarImagen(String str,boolean center) {
	
	editor.replaceSelection(Analizador.agregarImagen(str,center));
	
}

public void generarGvideo(String str,boolean link) {
	
	editor.replaceSelection(Analizador.agregarGvideo(str,link));
	
}


public void generarBliptv(String str,boolean link) {
	
	editor.replaceSelection(Analizador.agregarBliptv(str,link));
	
}

public void generarVimeo(String str,boolean link) {
	
	editor.replaceSelection(Analizador.agregarVimeo(str,link));
	
}


public void generarDailyMotion(String str,boolean link) {
	
	editor.replaceSelection(Analizador.agregarDailyMotion(str,link));
	
}

public void generarMetacafe(String str,boolean link) {
	
	editor.replaceSelection(Analizador.agregarMetacafe(str,link));
	
}


public void generarSwf(String str,boolean link) {
	
	editor.replaceSelection(Analizador.agregarSwf(str,link));
	
}
	


	private void goearMouseClicked(MouseEvent evt) {
		String seleccion=editor.getSelectedText();
		if (!(dialogo.isVisible() | (dialogo2.isVisible()))) {
		if (seleccion != null) 
				
			editor.replaceSelection(Analizador.agregarGoear(seleccion,true));
		
		else
		{
			dialogo.setTipo("goear");
			dialogo.setLinkEnabled(true);
			dialogo.setTitle("Insertar cancion de GoEar");
			dialogo.cambiarLabel("Ingresa la URL completa");
			dialogo.setVisible(true);
						
		}
		dialogo.obtenerFoco();
		}
	}
	
	
		
/*
	private void linkMouseClicked(MouseEvent evt) {
		String seleccion=editor.getSelectedText();
		
		if (!(dialogo.isVisible() | (dialogo2.isVisible()))) {
			if (!esImagen(seleccion)) 
				{
				dialogo2.setTipo("link");
				dialogo2.setTitle("Insertar Link");
				}
			else
			{
				dialogo2.setTipo("imagen");
				dialogo2.setTitle("Insertar Imagen con Link");
			}
			dialogo2.setDefaultButton();
					if (seleccion != null)
			{
			if (esImagen(seleccion)) dialogo2.setTexto(getImagen(seleccion));
				else
				dialogo2.setTexto(seleccion);
								
			}	
				
			
			dialogo2.setVisible(true);
			dialogo2.urlRequestFocus();
			
			
			}
		
			
		}
		*/
		
	private void linkMouseClicked(MouseEvent evt) {
		String seleccion=editor.getSelectedText();
		
		if (!(dialogo.isVisible() | (dialogo2.isVisible()))) {
		
		
				dialogo2.setTipo("link");
				dialogo2.setTitle("Insertar Link");
				}
			else
			{
				dialogo2.setTipo("imagen");
				dialogo2.setTitle("Insertar Imagen con Link");
				
			}
			dialogo2.setDefaultButton();
			dialogo2.setTexto(seleccion);
			dialogo2.setVisible(true);
			dialogo2.urlRequestFocus();
			
			
			}
		
			
		
	
	
	private void imglnkMouseClicked(MouseEvent evt) {
		String seleccion=editor.getSelectedText();
		
		
		if (!(dialogo.isVisible() | (dialogo2.isVisible()))) {
		dialogo2.setTipo("imagen");
		dialogo2.setTitle("Insertar Imagen con link");
		
		dialogo2.setDefaultButton();
		if (seleccion != null)
		{
			if (esImagen(seleccion)) dialogo2.setTexto(getImagen(seleccion));
			else 
			dialogo2.setTexto(seleccion);
							
		}	
		dialogo2.setVisible(true);
		
		}
		dialogo2.urlRequestFocus();
		
	}
	
	private void gvideoMouseClicked(MouseEvent evt) {
		String seleccion=editor.getSelectedText();
		if (!(dialogo.isVisible() | (dialogo2.isVisible()))) {
			if (seleccion != null) 
		
			editor.replaceSelection(Analizador.agregarGvideo(seleccion,true));
		
			else
		{
			dialogo.setTipo("gvideo");
			dialogo.setLinkEnabled(true);
			dialogo.setTitle("Insertar video desde Google Video");
			dialogo.cambiarLabel("Ingresa la URL completa");
			dialogo.setVisible(true);
		}
	}
		dialogo.obtenerFoco();
	}
	
	
	private void youtubeMouseClicked(MouseEvent evt) {
		String seleccion=editor.getSelectedText();
		if (!(dialogo.isVisible() | (dialogo2.isVisible()))) {
			if (seleccion != null) 
				
			editor.replaceSelection(Analizador.agregarVideo(seleccion,false,true));
		
			else
		{
			dialogo.setTipo("youtube");
			dialogo.setLinkEnabled(true);
			dialogo.setTitle("Insertar video desde Youtube");
			dialogo.cambiarLabel("Ingresa la URL completa");
			dialogo.setVisible(true);
						
		}
	}
		dialogo.obtenerFoco();
	}
	
	
	 private void vimeoActionPerformed(ActionEvent evt) {
		 String seleccion=editor.getSelectedText();
			if (!(dialogo.isVisible() | (dialogo2.isVisible()))) {
				if (seleccion != null) 
					
				editor.replaceSelection(Analizador.agregarVimeo(seleccion,true));
			
				else
			{
				dialogo.setTipo("vimeo");
				dialogo.setLinkEnabled(true);
				dialogo.setTitle("Insertar video desde Vimeo");
				dialogo.cambiarLabel("Ingresa la URL completa");
				dialogo.setVisible(true);
							
			}
		}
			dialogo.obtenerFoco();
		
	    }
	
	
	private void megavideoMouseClicked(MouseEvent evt) {
		String seleccion=editor.getSelectedText();
		if (!(dialogo.isVisible() | (dialogo2.isVisible()))) {
			if (seleccion != null) 
				
			editor.replaceSelection(Analizador.agregarMegavideo(seleccion,true));
		
			else
		{
			dialogo.setTipo("megavideo");
			dialogo.setLinkEnabled(true);
			dialogo.setTitle("Insertar video desde MegaVideo");
			dialogo.cambiarLabel("Ingresa la URL completa");
			dialogo.setVisible(true);
						
		}
	}
		dialogo.obtenerFoco();
	}
	
	
	
	
	
	private void swfMouseClicked(MouseEvent evt) {
		String seleccion=editor.getSelectedText();
		if (!(dialogo.isVisible() | (dialogo2.isVisible()))) {
			if (seleccion != null) 
				
			editor.replaceSelection(Analizador.agregarSwf(seleccion,true));
		
			else
		{
			dialogo.setTipo("swf");
			dialogo.setLinkEnabled(true);
			dialogo.setTitle("Insertar archivo SWF");
			dialogo.setVisible(true);
						
		}
		}
		dialogo.obtenerFoco();
	}

	
	private void imgMouseClicked(MouseEvent evt) {
		String seleccion=editor.getSelectedText();
		
		if (!(dialogo.isVisible() | (dialogo2.isVisible()))) {
			
	
			if (seleccion != null) 
			{
			editor.replaceSelection(Analizador.agregarImagen(seleccion,false));
		editor.requestFocus();
			}
			else
		{
			dialogo.setTipo("imagen");
			dialogo.setLinkEnabled(false);
			dialogo.setTitle("Insertar imagen");
			dialogo.setVisible(true);
						
		}
	}
		dialogo.obtenerFoco();
	}
	
private void subMouseClicked(MouseEvent evt) {
		
	aplicar_sub();
	}
	
	private void negritaMouseClicked(MouseEvent evt) {
		aplicar_negrita();		
	}
	
	
	private void aplicar_sub() {
String seleccion=editor.getSelectedText();
		
		if (seleccion != null)   {
			int inicio,fin;
			inicio=editor.getSelectionStart();
		editor.replaceSelection("[u]"+seleccion+"[/u]");
		fin=editor.getCaretPosition();
		editor.setSelectionStart(inicio);
		editor.setSelectionEnd(fin);
		}
		else{
			int posicion=editor.getCaretPosition();	
			editor.replaceSelection("[u]"+"[/u]");
			editor.setCaretPosition(posicion+3);
		}
		editor.requestFocus();
		
	}
	
	
private void aplicar_negrita() {
	String seleccion=editor.getSelectedText();
	if (seleccion != null)  {
		int inicio,fin;
		inicio=editor.getSelectionStart();
	editor.replaceSelection("[b]"+seleccion+"[/b]");
	fin=editor.getCaretPosition();
	editor.setSelectionStart(inicio);
	editor.setSelectionEnd(fin);
	}
	else
	{
		int posicion=editor.getCaretPosition();
		editor.replaceSelection("[b]"+"[/b]");
		editor.setCaretPosition(posicion+3);
		
		}
	editor.requestFocus();
}
	
	
private void aplicar_italica() {
	String seleccion=editor.getSelectedText();
	if (seleccion != null) {
	int inicio,fin;
	inicio=editor.getSelectionStart();
	editor.replaceSelection("[i]"+seleccion+"[/i]");
	fin=editor.getCaretPosition();
	editor.setSelectionStart(inicio);
	editor.setSelectionEnd(fin);
	}
	else{
		int posicion=editor.getCaretPosition();
		editor.replaceSelection("[i]"+"[/i]");
		editor.setCaretPosition(posicion+3);
		}
	editor.requestFocus();
}


	private void italicaMouseClicked(MouseEvent evt) {
		aplicar_italica();
	}
	
	
	private void izqMouseClicked(MouseEvent evt) {
		alinearIzq();
	}
	
	private void centerMouseClicked(MouseEvent evt) {
		alinearCentro();
	}
	
	private void derMouseClicked(MouseEvent evt) {
		alinearDerecha();
		}
	
	private void alinearIzq() {
    	String seleccion=editor.getSelectedText();
		if (seleccion != null)  {
			int inicio,fin;
			inicio=editor.getSelectionStart();
		editor.replaceSelection("[align=left]"+seleccion+"[/align]");
		fin=editor.getCaretPosition();
		editor.setSelectionStart(inicio);
		editor.setSelectionEnd(fin);
		editor.requestFocus();
		}
		else {
			editor.replaceSelection("[align=left]"+"[/align]");
			editor.requestFocus();
			editor.setCaretPosition(editor.getCaretPosition()-8);
			}
    }
	
	private void alinearCentro() {
		String seleccion=editor.getSelectedText();
		if (seleccion != null)  {
			int inicio,fin;
			inicio=editor.getSelectionStart();
		editor.replaceSelection("[align=center]"+seleccion+"[/align]");
		fin=editor.getCaretPosition();
		editor.setSelectionStart(inicio);
		editor.setSelectionEnd(fin);
		editor.requestFocus();
		}
		else {
			editor.replaceSelection("[align=center]"+"[/align]");
			editor.requestFocus();
			editor.setCaretPosition(editor.getCaretPosition()-8);
		}
	}
	
	private void alinearDerecha() {
		String seleccion=editor.getSelectedText();
		if (seleccion != null)  {
			int inicio,fin;
			inicio=editor.getSelectionStart();
		editor.replaceSelection("[align=right]"+seleccion+"[/align]");
		fin=editor.getCaretPosition();
		editor.setSelectionStart(inicio);
		editor.setSelectionEnd(fin);
		editor.requestFocus();
		}
		else {
			editor.replaceSelection("[align=right]"+"[/align]");
			editor.requestFocus();
			editor.setCaretPosition(editor.getCaretPosition()-8);
		}
	}
	
	
	
	
	
	
	private JComboBox getcolores() {
		if(colores == null) {
			ComboBoxModel coloresModel = 
				new DefaultComboBoxModel(stringColores);
			colores = new JComboBox();
			colores.setModel(coloresModel);
			
			colores.setFont(new java.awt.Font("Arial",0,12));
			colores.setSelectedIndex(0);
			colores.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent evt) {
					coloresActionPerformed(evt);
				}
			});
		}
		return colores;
	}
	
	private JComboBox getCmbTamaño() {
		if(cmbTamaño == null) {
			ComboBoxModel comboModel = 
				new DefaultComboBoxModel(stringSizes);
			cmbTamaño = new JComboBox();
			cmbTamaño.setModel(comboModel);
			cmbTamaño.setFont(new java.awt.Font("Arial",0,12));
			cmbTamaño.setSelectedIndex(0);
			cmbTamaño.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent evt) {
					cmbTamañoActionPerformed(evt);
				}
			});
		}
		return cmbTamaño;
	}
	
	
	private JComboBox getFonts() {
		if(fonts == null) {
			fonts = new JComboBox();
			fonts.setModel(fontsModel);
			fonts.setSelectedIndex(0);
			fonts.setToolTipText("Fuente");
			fonts.setFont(new java.awt.Font("Arial",0,12));
			fonts.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent evt) {
					fontsActionPerformed(evt);
				}
			});
		}
		return fonts;
		
	}

	private void coloresActionPerformed(ActionEvent evt) {
		tags_colores();
	}
	
	private void cmbTamañoActionPerformed(ActionEvent evt) {
tags_tamanio();
	}
	
	private void tags_colores() {
		String seleccion=editor.getSelectedText();
		if (seleccion == null) seleccion="";
		int inicio,fin;
		inicio=editor.getSelectionStart();
	
	
			int select = colores.getSelectedIndex();
			switch (select) {
			case 1:  {colores.setSelectedIndex(0);
						editor.replaceSelection("[color=darkred]"+seleccion+"[/color]");
						fin=editor.getCaretPosition();
						if (seleccion !=""){
								editor.setSelectionStart(inicio);
								editor.setSelectionEnd(fin);}
					break;
					}
			case 2:  {colores.setSelectedIndex(0);
						editor.replaceSelection("[color=red]"+seleccion+"[/color]");
						fin=editor.getCaretPosition();
						if (seleccion !=""){
								editor.setSelectionStart(inicio);
								editor.setSelectionEnd(fin);}
					break;
					}
			case 3:  {
					colores.setSelectedIndex(0);
					editor.replaceSelection("[color=orange]"+seleccion+"[/color]");
					fin=editor.getCaretPosition();
					if (seleccion !=""){
							editor.setSelectionStart(inicio);
							editor.setSelectionEnd(fin);}
					break;
					}
			case 4:  {
						colores.setSelectedIndex(0);
						editor.replaceSelection("[color=brown]"+seleccion+"[/color]");
						fin=editor.getCaretPosition();
						if (seleccion !=""){
								editor.setSelectionStart(inicio);
								editor.setSelectionEnd(fin);}
						break;
						}
			case 5:  {
						colores.setSelectedIndex(0);
						editor.replaceSelection("[color=yellow]"+seleccion+"[/color]");
						fin=editor.getCaretPosition();
						if (seleccion !=""){
								editor.setSelectionStart(inicio);
								editor.setSelectionEnd(fin);}
						break;
						}
			case 6:  {
				colores.setSelectedIndex(0);
				editor.replaceSelection("[color=green]"+seleccion+"[/color]");
				fin=editor.getCaretPosition();
				if (seleccion !=""){
						editor.setSelectionStart(inicio);
						editor.setSelectionEnd(fin);}
				break;
				}
			case 7:  {
				colores.setSelectedIndex(0);
				editor.replaceSelection("[color=olive]"+seleccion+"[/color]");
				fin=editor.getCaretPosition();
				if (seleccion !=""){
						editor.setSelectionStart(inicio);
						editor.setSelectionEnd(fin);}
				break;
				}
			case 8:  {
				colores.setSelectedIndex(0);
				editor.replaceSelection("[color=cyan]"+seleccion+"[/color]");
				fin=editor.getCaretPosition();
				if (seleccion !=""){
						editor.setSelectionStart(inicio);
						editor.setSelectionEnd(fin);}
				break;
				}
			case 9:  {
				colores.setSelectedIndex(0);
				editor.replaceSelection("[color=blue]"+seleccion+"[/color]");
				fin=editor.getCaretPosition();
				if (seleccion !=""){
						editor.setSelectionStart(inicio);
						editor.setSelectionEnd(fin);}
				break;
				}
			case 10:  {
				colores.setSelectedIndex(0);
				editor.replaceSelection("[color=darkblue]"+seleccion+"[/color]");
				fin=editor.getCaretPosition();
				if (seleccion !=""){
						editor.setSelectionStart(inicio);
						editor.setSelectionEnd(fin);}
				break;
				}
			case 11:  {
				colores.setSelectedIndex(0);
				editor.replaceSelection("[color=indigo]"+seleccion+"[/color]");
				fin=editor.getCaretPosition();
				if (seleccion !=""){
						editor.setSelectionStart(inicio);
						editor.setSelectionEnd(fin);}
				break;
				}
			case 12:  {
				colores.setSelectedIndex(0);
				editor.replaceSelection("[color=violet]"+seleccion+"[/color]");
				fin=editor.getCaretPosition();
				if (seleccion !=""){
						editor.setSelectionStart(inicio);
						editor.setSelectionEnd(fin);}
				break;
				}
			case 13:  {
				colores.setSelectedIndex(0);
				editor.replaceSelection("[color=black]"+seleccion+"[/color]");
				fin=editor.getCaretPosition();
				if (seleccion !=""){
						editor.setSelectionStart(inicio);
						editor.setSelectionEnd(fin);}
				break;
				}
			
			case 14:  {
			
				mostrarColorChooser();
				
				break;
				}
			
			
				
		}
			
		
			colores.setSelectedIndex(0);
			editor.requestFocus();
	}
	
	private void tags_tamanio() {
		String seleccion=editor.getSelectedText();
		if (seleccion == null) seleccion="";
		int inicio,fin;
		inicio=editor.getSelectionStart();
	
	
		int select = cmbTamaño.getSelectedIndex();
			switch (select) {
			case 1:  {
				cmbTamaño.setSelectedIndex(0);
				editor.replaceSelection("[size=9]"+seleccion+"[/size]");
				fin=editor.getCaretPosition();
				if (seleccion !=""){
						editor.setSelectionStart(inicio);
						editor.setSelectionEnd(fin);}
				break;
				}
			case 2:  {
				cmbTamaño.setSelectedIndex(0);
				editor.replaceSelection("[size=12]"+seleccion+"[/size]");
				fin=editor.getCaretPosition();
				if (seleccion !=""){
						editor.setSelectionStart(inicio);
						editor.setSelectionEnd(fin);}
				break;
				}
			case 3:  {
				cmbTamaño.setSelectedIndex(0);
				editor.replaceSelection("[size=14]"+seleccion+"[/size]");
				fin=editor.getCaretPosition();
				if (seleccion !=""){
						editor.setSelectionStart(inicio);
						editor.setSelectionEnd(fin);}
				break;
				}
			case 4:  {
				cmbTamaño.setSelectedIndex(0);
				editor.replaceSelection("[size=16]"+seleccion+"[/size]");
				fin=editor.getCaretPosition();
				if (seleccion !=""){
						editor.setSelectionStart(inicio);
						editor.setSelectionEnd(fin);}
				break;
				}
			case 5:  {
				cmbTamaño.setSelectedIndex(0);
				editor.replaceSelection("[size=18]"+seleccion+"[/size]");
				fin=editor.getCaretPosition();
				if (seleccion !=""){
						editor.setSelectionStart(inicio);
						editor.setSelectionEnd(fin);}
				break;
				}
			case 6:  {
				cmbTamaño.setSelectedIndex(0);
				editor.replaceSelection("[size=20]"+seleccion+"[/size]");
				fin=editor.getCaretPosition();
				if (seleccion !=""){
						editor.setSelectionStart(inicio);
						editor.setSelectionEnd(fin);}
				break;
				}
			case 7:  {
				cmbTamaño.setSelectedIndex(0);
				editor.replaceSelection("[size=22]"+seleccion+"[/size]");
				
				fin=editor.getCaretPosition();
				if (seleccion !=""){
						editor.setSelectionStart(inicio);
						editor.setSelectionEnd(fin);}
				break;
				}
			case 8:  {
				cmbTamaño.setSelectedIndex(0);
				editor.replaceSelection("[size=24]"+seleccion+"[/size]");
				fin=editor.getCaretPosition();
				if (seleccion !=""){
						editor.setSelectionStart(inicio);
						editor.setSelectionEnd(fin);}
				break;
				}
		}
		
			cmbTamaño.setSelectedIndex(0);
			editor.requestFocus();
	}
	
	private void fontsActionPerformed(ActionEvent evt) {
		insertarFuente();
	}
	
	
	
	private void tags_fuente(Object object,String seleccion) {
		editor.replaceSelection("[font="+object+"]"+seleccion+"[/font]");
	}
	
	private void insertarFuente(){
		String seleccion=editor.getSelectedText();
		if (seleccion == null) seleccion="";
		int inicio,fin;
		inicio=editor.getSelectionStart();
		tags_fuente(fonts.getSelectedItem(),seleccion);
		fonts.setSelectedIndex(0);
		fin=editor.getCaretPosition();
		if (seleccion !=""){
			editor.setSelectionStart(inicio);
			editor.setSelectionEnd(fin);
	
			}
			
						
			fonts.setSelectedIndex(0);
			editor.requestFocus();
	}
	
	
	
	
	
	
	private JMenu getJMenu1() {
		if(jMenu1 == null) {
			jMenu1 = new JMenu();
			jMenu1.setText("Menu");
			jMenu1.setFont(arialPlain12);
			//jMenu1.setBackground(new java.awt.Color(255,255,255));
			//jMenu1.setForeground(new java.awt.Color(0,0,0));
			jMenu1.add(getNuevo());
			jMenu1.add(getJSeparator5());
			jMenu1.add(getConfigEstilos());
			jMenu1.add(getJSeparator1());
			jMenu1.add(getJMenuItem1());
		}
		return jMenu1;
	}

	
	private JMenuItem getBuscarAct() {
		if(buscarAct == null) {
			buscarAct = new JMenuItem();
			buscarAct.setText("Buscar actualizaciones");
			buscarAct.setBounds(81, 19, 148, 22);
			buscarAct.setFont(new java.awt.Font("Arial",0,12));
			//buscarAct.setBackground(new java.awt.Color(255,255,255));
						
			buscarAct.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent evt) {
					buscarActActionPerformed(evt);
				}
			});
		}
		return buscarAct;
	}
	
	private JMenuItem getJMenuItem1() {
		if(jMenuItem1 == null) {
			jMenuItem1 = new JMenuItem();
			jMenuItem1.setText("Salir");
			jMenuItem1.setAccelerator(KeyStroke.getKeyStroke("ctrl pressed X"));
			jMenuItem1.setFont(new java.awt.Font("Arial",0,12));
			//jMenuItem1.setBackground(new java.awt.Color(255,255,255));
			jMenuItem1.addActionListener(

			         new ActionListener() { 

			            
			            public void actionPerformed( ActionEvent evento )
			            {
			               salir();
			            }

			         }  

			      ); 
		
		
		}
		return jMenuItem1;
	}
	
	
	
	
	
	private JMenuItem getJMenuItem2() {
		if(jMenuItem2 == null) {
			jMenuItem2 = new JMenuItem();
			jMenuItem2.setText("Acerca de...");
			jMenuItem2.setBounds(-73, -2, 147, 22);
			jMenuItem2.setFont(new java.awt.Font("Arial",0,12));
		//	jMenuItem2.setBackground(new java.awt.Color(255,255,255));
			jMenuItem2.addActionListener(

			         new ActionListener() {  

			            
			            public void actionPerformed( ActionEvent evento )
			            {
			            	
			    			mostrarAcercaDe();
			            }

			         }  

			      ); 
		}
		return jMenuItem2;
	}
	
	private JButton getSalir() {
		if(salir == null) {
			salir = new JButton(new ImageIcon(Main.class.getResource("exit.png")));
			salir.setText("Salir");
			salir.setFont(fuenteBoton);
			salir.setPreferredSize(new java.awt.Dimension(90, 90));
			salir.setSize(197, 30);
			salir.addMouseListener(new MouseAdapter() {
				public void mouseClicked(MouseEvent evt) {
					salirMouseClicked(evt);
				}
			});
		}
		return salir;
	}
	
	
	
	private void salir() {
		int i =JOptionPane.showConfirmDialog(this,"¿Estás seguro?","Salir de PosT!NGA",JOptionPane.YES_NO_OPTION);
		if(i==0){
		System.exit(0);
		}
	}
	
	private void salirMouseClicked(MouseEvent evt) {
		salir();
		
	}
	
	
	
		
	private void copiarMouseClicked(MouseEvent evt) {
		editor.selectAll();
        editor.copy();
		
	}
	
	

	private JPopupMenu getPopup1() {
		if(popup1 == null) {
			popup1 = new JPopupMenu();
			titulo.setComponentPopupMenu (popup1);
			jTags.setComponentPopupMenu (popup1);
			popup1.add(getPopCortar1());
			popup1.add(getPopCopiar1());
			popup1.add(getPopPegar1());
			popup1.add(getPopSelAll1());
			
		}
		return popup1;
		}
	
	
	
	private JTextField getJTags() {
		if(jTags == null) {
			jTags = new JTextField();
		}
		jTags.addFocusListener(new FocusAdapter() {
			public void focusLost(FocusEvent evt) {
				jTagsFocusLost(evt);
			}
			public void focusGained(FocusEvent evt) {
				jTagsFocusGained(evt);
			}
		});
		initTags();
		return jTags;
	}
		
	private JMenuItem getPopCortar1() {
		if(PopCortar1 == null) {
			PopCortar1 = new JMenuItem("Cortar");
			PopCortar1.setIcon(new ImageIcon(getClass().getResource("cut.gif")));
			PopCortar1.setFont(new java.awt.Font("Ubuntu",0,12));
			PopCortar1.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent evt) {
					PopCortar1ActionPerformed(evt);
				}
			});
		}
			return PopCortar1;
		}
	
	private JMenuItem getPopCopiar1() {
		if(PopCopiar1 == null) {
			PopCopiar1 = new JMenuItem("Copiar");
			PopCopiar1.setFont(new java.awt.Font("Ubuntu",0,12));
			PopCopiar1.setIcon(new ImageIcon(getClass().getResource("copy.gif")));
			PopCopiar1.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent evt) {
					PopCopiar1ActionPerformed(evt);
				}
			});
		}
			return PopCopiar1;
		}
			
			
	private JMenuItem getPopPegar1() {
		if(PopPegar1 == null) {
			PopPegar1 = new JMenuItem("Pegar");
			PopPegar1.setIcon(new ImageIcon(getClass().getResource("paste.gif")));
			PopPegar1.setFont(new java.awt.Font("Ubuntu",0,12));
			PopPegar1.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent evt) {
					PopPegar1ActionPerformed(evt);
				}
			});
		}
			return PopPegar1;
		}
	
	
	
	private JMenuItem getPopSelAll1() {
		if(PopSelAll1 == null) {
			PopSelAll1 = new JMenuItem("Seleccionar todo");
			PopSelAll1.setIcon(new ImageIcon(getClass().getResource(icon_select_all)));
			PopSelAll1.setFont(new java.awt.Font("Ubuntu",0,12));
			PopSelAll1.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent evt) {
					PopSelAll1ActionPerformed(evt);
				}
			});	
		}
			return PopSelAll1;
		}
		
		
		
	
	
	
	private JPopupMenu getPopup() {
		if(popup == null) {
			popup = new JPopupMenu();
			editor.setComponentPopupMenu (popup);
			
			
			
			popup.add(sub_fuente);
			popup.add(sub_color);
			popup.add(sub_tam);
			popup.add(getSeparador());
			popup.add(sub_copiar);
			popup.add(sub_pegar);
			popup.add(getSelectall());
			popup.add(getCortar());
			
			sub_fuente.setFont(new java.awt.Font("Ubuntu",0,12));
			sub_color.setFont(new java.awt.Font("Ubuntu",0,12));
			sub_copiar.setFont(new java.awt.Font("Ubuntu",0,12));
			sub_pegar.setFont(new java.awt.Font("Ubuntu",0,12));
			sub_tam.setFont(new java.awt.Font("Ubuntu",0,12));
			sub_copiar.setIcon(new ImageIcon(getClass().getResource(icon_copy)));
			sub_pegar.setIcon(new ImageIcon(getClass().getResource(icon_paste)));
			
			
			
			sub_copiar.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent evt) {
					sub_copiarActionPerformed(evt);
				}
			});
			
			sub_pegar.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent evt) {
					sub_pegarActionPerformed(evt);
				}
			});

			sub_tam.add(f9px);
			f9px.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent evt) {
					f9pxActionPerformed(evt);
				}
			});
			sub_tam.add(f12px);
			f12px.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent evt) {
					f12pxActionPerformed(evt);
				}
			});
			sub_tam.add(f14px);
			f14px.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent evt) {
					f14pxActionPerformed(evt);
				}
			});
			sub_tam.add(f16px);
			f16px.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent evt) {
					f16pxActionPerformed(evt);
				}
			});
			sub_tam.add(f18px);
			f18px.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent evt) {
					f18pxActionPerformed(evt);
				}
			});
			sub_tam.add(f20px);
			f20px.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent evt) {
					f20pxActionPerformed(evt);
				}
			});
			sub_tam.add(f22px);
			f22px.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent evt) {
					f22pxActionPerformed(evt);
				}
			});
			sub_tam.add(f24px);
			f24px.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent evt) {
					f24pxActionPerformed(evt);
				}
			});

			sub_color.add(rojo_o);
			//		rojo_o.setBackground(colorRojoO);
			//		rojo_o.setForeground(colorBlanco);
			rojo_o.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent evt) {
					rojo_oActionPerformed(evt);
				}
			});
			
			sub_color.add(rojo);
			//		rojo.setBackground(colorRojo);
			//		rojo.setForeground(colorBlanco);
			rojo.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent evt) {
					rojoActionPerformed(evt);
				}
			});
			
			sub_color.add(naranja);
			//		naranja.setBackground(colorNaranja);
			//		naranja.setForeground(colorBlanco);
			naranja.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent evt) {
					naranjaActionPerformed(evt);
				}
			});
			
			
			sub_color.add(marron);
			//		marron.setBackground(colorMarron);
			//		marron.setForeground(colorBlanco);
			marron.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent evt) {
					marronActionPerformed(evt);
				}
			});
			
			
			sub_color.add(amarillo);
			//	amarillo.setBackground(colorAmarillo);
			amarillo.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent evt) {
					amarilloActionPerformed(evt);
				}
			});
			
			sub_color.add(verde);
		//	verde.setBackground(colorVerde);
		//	verde.setForeground(colorBlanco);
			verde.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent evt) {
					verdeActionPerformed(evt);
				}
			});
			
			
			sub_color.add(oliva);
		//	oliva.setBackground(colorOliva);
			oliva.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent evt) {
					olivaActionPerformed(evt);
				}
			});
			sub_color.add(cyan);
		//	cyan.setBackground(colorCyan);
			cyan.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent evt) {
					cyanActionPerformed(evt);
				}
			});
			sub_color.add(azul);
			//	azul.setBackground(colorAzul);
			//	azul.setForeground(colorBlanco);
			azul.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent evt) {
					azulActionPerformed(evt);
				}
			});
			sub_color.add(azul_o);
			//	azul_o.setBackground(colorAzulO);
			//	azul_o.setForeground(colorBlanco);
			azul_o.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent evt) {
					azul_oActionPerformed(evt);
				}
			});
			sub_color.add(indigo);
			//indigo.setBackground(colorIndigo);
			//indigo.setForeground(colorBlanco);
			indigo.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent evt) {
					indigoActionPerformed(evt);
				}
			});
			sub_color.add(violeta);
			//		violeta.setBackground(colorVioleta);
			//		violeta.setForeground(colorBlanco);
			violeta.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent evt) {
					violetaActionPerformed(evt);
				}
			});
			sub_color.add(negro);
			//		negro.setForeground(colorBlanco);
			//		negro.setBackground(colorNegro);
			negro.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent evt) {
					negroActionPerformed(evt);
				}
			});

			sub_color.add(customColor);
			//	negro.setForeground(colorBlanco);
			//	negro.setBackground(colorNegro);
			customColor.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent evt) {
					customColorActionPerformed(evt);
				}
			});
			
			sub_fuente.add(arial);
			arial.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent evt) {
					arialActionPerformed(evt);
				}
			});
			sub_fuente.add(arial_b);
			arial_b.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent evt) {
					arial_bActionPerformed(evt);
				}
			});
			sub_fuente.add(american);
			american.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent evt) {
					americanActionPerformed(evt);
				}
			});
			sub_fuente.add(calibri);
			calibri.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent evt) {
					calibriActionPerformed(evt);
				}
			});
			

			sub_fuente.add(century);
			century.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent evt) {
					centuryActionPerformed(evt);
				}
			});
			
			sub_fuente.add(comic);
			comic.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent evt) {
					comicActionPerformed(evt);
				}
			});
			sub_fuente.add(courier);
			courier.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent evt) {
					courierActionPerformed(evt);
				}
			});
			
			sub_fuente.add(chiller);
			chiller.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent evt) {
					chillerActionPerformed(evt);
				}
			});
			sub_fuente.add(fixed);
			fixed.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent evt) {
					fixedActionPerformed(evt);
				}
			});
			sub_fuente.add(french);
			french.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent evt) {
					frenchActionPerformed(evt);
				}
			});
			sub_fuente.add(georgia);
			georgia.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent evt) {
					georgiaActionPerformed(evt);
				}
			});
			sub_fuente.add(impact);
			impact.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent evt) {
					impactActionPerformed(evt);
				}
			});
			sub_fuente.add(lucida_c);
			lucida_c.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent evt) {
					lucida_cActionPerformed(evt);
				}
			});
			sub_fuente.add(lucida_s);
			lucida_s.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent evt) {
					lucida_sActionPerformed(evt);
				}
			});
			sub_fuente.add(monotype);
			monotype.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent evt) {
					monotypeActionPerformed(evt);
				}
			});
			sub_fuente.add(times);
			times.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent evt) {
					timesActionPerformed(evt);
				}
			});
			sub_fuente.add(tradicional);
			tradicional.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent evt) {
					tradicionalActionPerformed(evt);
				}
			});
			sub_fuente.add(trebuchet);
			trebuchet.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent evt) {
					trebuchetActionPerformed(evt);
				}
			});
			sub_fuente.add(ubuntu);
			ubuntu.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent evt) {
					ubuntuActionPerformed(evt);
				}
			});
			sub_fuente.add(verdana);
			verdana.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent evt) {
					verdanaActionPerformed(evt);
				}
			});

		}
		return popup;
	}
	
	/**
	* Auto-generated method for setting the popup menu for a component
	*/
	
	
	private JSeparator getSeparador() {
		if(separador == null) {
			separador = new JSeparator();
		}
		return separador;
	}
	
	
	private void insertarFuentePopup(Object object) {
		String seleccion=editor.getSelectedText();
		if (seleccion == null) seleccion="";
		int inicio,fin;
		inicio=editor.getSelectionStart();
		tags_fuente(object,seleccion);
		fin=editor.getCaretPosition();
		if (seleccion !=""){
			editor.setSelectionStart(inicio);
			editor.setSelectionEnd(fin);
	
			}
		editor.requestFocus();
	}
	
	
	private void americanActionPerformed(ActionEvent evt) {
		insertarFuentePopup(american.getText());
	}
	
	private void arialActionPerformed(ActionEvent evt) {
		
		insertarFuentePopup(arial.getText());
	}
	
	private void arial_bActionPerformed(ActionEvent evt) {
		insertarFuentePopup(arial_b.getText());
	}
	
	
	
	private void calibriActionPerformed(ActionEvent evt) {
		insertarFuentePopup(calibri.getText());
	}
	
	private void centuryActionPerformed(ActionEvent evt) {
		insertarFuentePopup(century.getText());
	}
	
	private void chillerActionPerformed(ActionEvent evt) {
		insertarFuentePopup(american.getText());
	}
	
	private void comicActionPerformed(ActionEvent evt) {
		insertarFuentePopup(comic.getText());
	}
	
	private void courierActionPerformed(ActionEvent evt) {
		insertarFuentePopup(courier.getText());
	}
		
	private void fixedActionPerformed(ActionEvent evt) {
		insertarFuentePopup(fixed.getText());
	}
	
	private void frenchActionPerformed(ActionEvent evt) {
		insertarFuentePopup(french.getText());
	}
	
	private void georgiaActionPerformed(ActionEvent evt) {
		insertarFuentePopup(georgia.getText());
	}
	
	private void impactActionPerformed(ActionEvent evt) {
		insertarFuentePopup(impact.getText());
	}
	
	private void lucida_cActionPerformed(ActionEvent evt) {
		insertarFuentePopup(lucida_c.getText());
	}
	
	private void lucida_sActionPerformed(ActionEvent evt) {
		insertarFuentePopup(lucida_s.getText());
	}
	
	private void monotypeActionPerformed(ActionEvent evt) {
		insertarFuentePopup(monotype.getText());
	}
	
	private void timesActionPerformed(ActionEvent evt) {
		insertarFuentePopup(times.getText());
	}
	
	private void tradicionalActionPerformed(ActionEvent evt) {
		insertarFuentePopup(tradicional.getText());
	}
	
	private void trebuchetActionPerformed(ActionEvent evt) {
		insertarFuentePopup(trebuchet.getText());
	}
	
	private void ubuntuActionPerformed(ActionEvent evt) {
		insertarFuentePopup(ubuntu.getText());
	}
	
	private void verdanaActionPerformed(ActionEvent evt) {
		insertarFuentePopup(verdana.getText());
	}
	
	private void sub_copiarActionPerformed(ActionEvent evt) {
		editor.copy();
	
		
	}

	private void sub_pegarActionPerformed(ActionEvent evt) {
			
		pegadoInteligente();
		editor.requestFocus();
	}
	
	/**
	* Auto-generated method for setting the popup menu for a component
	*/
	
	
	
	

	
	public String getClipboardContents() {
	    String result = "";
	    Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
	    //odd: the Object param of getContents is not currently used
	    Transferable contents = clipboard.getContents(null);
	    boolean hasTransferableText =
	      (contents != null) &&
	      contents.isDataFlavorSupported(DataFlavor.stringFlavor)
	    ;
	    if ( hasTransferableText ) {
	      try {
	        result = (String)contents.getTransferData(DataFlavor.stringFlavor);
	      }
	      catch (UnsupportedFlavorException ex){
	        //highly unlikely since we are using a standard DataFlavor
	        
	        ex.printStackTrace();
	      }
	      catch (IOException ex) {
	        
	        ex.printStackTrace();
	      }
	    }
	    return result;
	  }
	
	
	
	private void rojo_oActionPerformed(ActionEvent evt) {
		colores.setSelectedIndex(1);
		tags_colores();
	}
	
	private void rojoActionPerformed(ActionEvent evt) {
		colores.setSelectedIndex(2);
		tags_colores();
	}
	
	private void naranjaActionPerformed(ActionEvent evt) {
		colores.setSelectedIndex(3);
		tags_colores();
	}
	
	private void marronActionPerformed(ActionEvent evt) {
		colores.setSelectedIndex(4);
		tags_colores();
	}
	
	private void amarilloActionPerformed(ActionEvent evt) {
		colores.setSelectedIndex(5);
		tags_colores();
	}	
		
	
	private void verdeActionPerformed(ActionEvent evt) {
		colores.setSelectedIndex(6);
		tags_colores();
	}
	
	private void olivaActionPerformed(ActionEvent evt) {
		colores.setSelectedIndex(7);
		tags_colores();
	}
	
	private void cyanActionPerformed(ActionEvent evt) {
		colores.setSelectedIndex(8);
		tags_colores();
	}
	
	private void azulActionPerformed(ActionEvent evt) {
		colores.setSelectedIndex(9);
		tags_colores();
	}
	
	private void azul_oActionPerformed(ActionEvent evt) {
		colores.setSelectedIndex(10);
		tags_colores();
	}
	
	private void indigoActionPerformed(ActionEvent evt) {
		colores.setSelectedIndex(11);
		tags_colores();
	}
	
	private void violetaActionPerformed(ActionEvent evt) {
		colores.setSelectedIndex(12);
		tags_colores();
	}
	
	private void negroActionPerformed(ActionEvent evt) {
		colores.setSelectedIndex(13);
		tags_colores();
	}
	
	
	private void customColorActionPerformed(ActionEvent evt) {
		mostrarColorChooser();
		
	}
	
	
	public void insertarColor(String str){
		String seleccion=editor.getSelectedText();
		if (seleccion == null) seleccion="";
		int inicio,fin;
		inicio=editor.getSelectionStart();
		colores.setSelectedIndex(0);
		editor.replaceSelection("[color=#"+str+"]"+seleccion+"[/color]");
		fin=editor.getCaretPosition();
		if (seleccion !=""){
				editor.setSelectionStart(inicio);
				editor.setSelectionEnd(fin);}
		
		
	}
	
	
	private void mostrarColorChooser()
	{
		if (colorCh==null) {
			colorCh= new ColorChooser(this);
			colorCh.conectar(this);
			colorCh.setLocationRelativeTo(null);
		}
		colorCh.setVisible(true);
		
	}
	
	private JButton getLater() {
		if(later == null) {
			later = new JDropDownButton();
			final JMenuItem jMenuItem1=new JMenuItem("en Disco");
			jMenuItem1.setFont(new java.awt.Font("Arial",0,12));
			final JMenuItem jMenuItem2=new JMenuItem("en la Web");
			jMenuItem2.setFont(new java.awt.Font("Arial",0,12));
			later.add(jMenuItem1);
			later.add(jMenuItem2);
			later.setText("Guardar borrador");
			later.setIcon(new ImageIcon(getClass().getResource("guardarB.png")));
			later.setToolTipText("Guarda borrador del post (Ctrl-S)");
			later.setFont(fuenteBoton);
			later.setPreferredSize(new java.awt.Dimension(166, 29));
			later.setSize(171, 29);

			later.addActionListener(new ActionListener() {	
				public void actionPerformed(ActionEvent evt) {
					if (later.getEventSource() != null) {
				        if (later.getEventSource() == jMenuItem1) {
				              try {
								guardar_borrador();
							} catch (Exception e) {
								// TODO Auto-generated catch block
								e.printStackTrace();
							}
				        } else if (later.getEventSource() == jMenuItem2) {
				        	try {
				        		if (login(config.getUsuario(),config.getContrasenia()) && modo==0)	guardarBorradorOnlineT();
				        		if (login(config.getUsuario(),config.getContrasenia()) && modo==2)	guardarBorradorOnlineP();
				        		
							} catch (Exception e) {
								JOptionPane.showMessageDialog( Main.this,"No se pudo establecer la conexión con el servidor.\n Chequea tu conexión a internet","Ups", JOptionPane.ERROR_MESSAGE );
							}
				        }
				} 
				}
			});
		}
		return later;
	}
	
	private JDropDownButton getJDropDownButton1() {
		if(cargarBorrador == null) {
			cargarBorrador = new JDropDownButton();
			cargarBorrador.setText("Cargar borrador");
			cargarBorrador.setIcon(new ImageIcon(getClass().getResource("cargarB.png")));
			final JMenuItem jMenuItem3=new JMenuItem("Desde disco");
			jMenuItem3.setFont(new java.awt.Font("Arial",0,12));
			final JMenuItem jMenuItem4=new JMenuItem("Desde la web");
			jMenuItem4.setFont(new java.awt.Font("Arial",0,12));
			cargarBorrador.add(jMenuItem3);
			cargarBorrador.add(jMenuItem4);
			cargarBorrador.setFont(fuenteBoton);
			cargarBorrador.setPreferredSize(new java.awt.Dimension(166, 29));
			cargarBorrador.setToolTipText("Cargar borrador (Ctrl-O)");
			cargarBorrador.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent evt) {
					if (cargarBorrador.getEventSource() != null) {
						
						if (cargarBorrador.getEventSource() == jMenuItem3) {
							try {
								if (cargar_borrador()){
							    	JOptionPane.showMessageDialog( Main.this,"Borrador cargado",
							                "Cargar borrador", JOptionPane.INFORMATION_MESSAGE );
							    	
							    	}
							} catch (Exception e) {
								// TODO Auto-generated catch block
								e.printStackTrace();
							}
						} else if (cargarBorrador.getEventSource() == jMenuItem4) {
							try {
								if (login(config.getUsuario(),config.getContrasenia()))	verBorradores();
								
							} catch (Exception e) {
								JOptionPane.showMessageDialog( Main.this,"No se pudo establecer la conexión con el servidor.\n Chequea tu conexión a internet","Ups", JOptionPane.ERROR_MESSAGE );
							}
						}
					} 
				}
			});
			
		}
		return cargarBorrador;
	}

	
	
	private void autoGuardarPost() {
		
		StreamResult result;
		TransformerFactory transformerFactory = TransformerFactory.newInstance();
		Transformer transformer;
		try {
			transformer = transformerFactory.newTransformer();
		
		DOMSource source = new DOMSource(guardarXML());
		
		
		String archivo = null;
		
		if (config.esLinux()) archivo=System.getProperty("user.home")+"/autoguardado.xml";
		else archivo=System.getProperty("user.home")+"\\autoguardado.xml";
		
		
		result = new StreamResult(new File(archivo));
		 
		transformer.transform(source, result);

		} catch (TransformerConfigurationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (TransformerException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	
	public void guardar_borrador() throws IOException, TransformerException {
		StreamResult result;
		TransformerFactory transformerFactory = TransformerFactory.newInstance();
		Transformer transformer = transformerFactory.newTransformer();
		DOMSource source = new DOMSource(guardarXML());
		
		JFileChooser fc = new JFileChooser( "./data/" );
        fc.setDialogTitle( "Guardar como... " );
        fc.setFileSelectionMode( JFileChooser.FILES_ONLY );
        fc.setMultiSelectionEnabled( false ); 
        FileNameExtensionFilter filter = new FileNameExtensionFilter("Archivos .xml", "xml");
		// Al selector se le agrega el filtro que se acaba de crear
		 fc.setFileFilter(filter); 

        boolean termine = false;

        int resultado = fc.showSaveDialog( this );

        while( !termine )
        {
            if( resultado == JFileChooser.APPROVE_OPTION )
            {
                File archivo = fc.getSelectedFile( );

                int respuesta = JOptionPane.YES_OPTION;

                // Si el archivo ya existe hay que pedir confirmaciÛn
                // para
                // sobreescribirlo
                if( archivo.exists( ) )
                {
                    respuesta = JOptionPane.showConfirmDialog( this, "¿Sobreescribir el archivo seleccionado?", "Sobreescribir", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE );
                }

                // Si la respuesta fue positiva (o si no fue necesario
                // hacer la
                // pregunta) se graba el archivo
                if( respuesta == JOptionPane.YES_OPTION )
                {
                	
              			
              			if(archivo.getName().contains(".xml"))	result = new StreamResult(new File(archivo+""));
              			else result = new StreamResult(new File(archivo+".xml"));
               		 
                		transformer.transform(source, result);
            	
            			    JOptionPane.showMessageDialog( Main.this,"El borrador fue guardado",
            		                "Guardar borrador", JOptionPane.PLAIN_MESSAGE );
                        termine = true;
                  
                }
                else
                {
                    resultado = fc.showSaveDialog( this );
                }
            }
            else
            {
                termine = true;
            }
        }
		 
		 
		 
		 
		 
		 
	}
	
	/* public void guardar_borrador() throws IOException {
		
	
		 BufferedWriter out;
		 File fichero = null;
		 JFileChooser fileChooser = new JFileChooser();
		 FileNameExtensionFilter filter = new FileNameExtensionFilter("Archivos .txt", "txt");
		// Al selector se le agrega el filtro que se acaba de crear
		 fileChooser.setFileFilter(filter); 
  		int seleccion = fileChooser.showSaveDialog(this);
  		if (seleccion == JFileChooser.APPROVE_OPTION)
  		{
  		    fichero = fileChooser.getSelectedFile();
  		   
  		
  		
  		if(fichero.getName().contains(".txt"))	out = new BufferedWriter(new FileWriter(fichero));
  			else 	out = new BufferedWriter(new FileWriter(fichero+".txt"));
  			
		 
	
			    out.write("[Titulo]\n");
			    if (titulo.getText().equals(tituloDefault))  out.write(""); else out.write(titulo.getText());
			    out.write("\n");
			    out.write("[Fuente]\n");
			    out.write(source.getText());out.write("\n");
			    out.write("[Post]\n");
			    out.write(editor.getText());
			    out.close();
			    JOptionPane.showMessageDialog( Main.this,"El borrador fue guardado",
		                "Guardar borrador", JOptionPane.PLAIN_MESSAGE );
  		}
		
	 }
		*/ 
         public boolean cargar_borrador() throws Exception {
        	 File fichero = null;
        	 boolean retorno=false;
     
        	 JFileChooser fileChooser = new JFileChooser();
        	 FileNameExtensionFilter filter = new FileNameExtensionFilter("Archivos .xml", "xml");
     		// Al selector se le agrega el filtro que se acaba de crear
     		 fileChooser.setFileFilter(filter); 
        	 
     		int seleccion = fileChooser.showOpenDialog(this);
     		if (seleccion == JFileChooser.APPROVE_OPTION)
     		{
     		    fichero = fileChooser.getSelectedFile();
     		   
     		}
     		
     	if (fichero!=null) {
	            
	          leerXML(fichero);
     	}
     	  return retorno;  
        	 
         }

	 
	    
	    private JMenuItem getAbrirB() {
	    	if(abrirB == null) {
	    		abrirB = new JMenuItem();
	    		abrirB.setText("Cargar borrador");
	    		abrirB.setBounds(-102, 43, 118, 22);
	    		//abrirB.setBackground(new java.awt.Color(255,255,255));
	    		abrirB.setFont(new java.awt.Font("Arial",0,12));
	    		abrirB.setAccelerator(KeyStroke.getKeyStroke("ctrl pressed O"));
	    		abrirB.addActionListener(new ActionListener() {
	    			public void actionPerformed(ActionEvent evt) {
	    				try {
							abrirBActionPerformed(evt);
						} 
	    				 catch (Exception e) {
							
							e.printStackTrace();
						}
	    			}
	    		});
	    	}
	    	return abrirB;
	    }
	    
	    private void abrirBActionPerformed(ActionEvent evt) throws Exception {
	   
	    	if (cargar_borrador()){
	    	JOptionPane.showMessageDialog( Main.this,"Borrador cargado",
	                "Cargar borrador", JOptionPane.INFORMATION_MESSAGE );
	    	
	    	}
	    	
	    }
	    
	    private JMenuItem getSelectall() {
	    	if(selectall == null) {
	    		selectall = new JMenuItem();
	    		selectall.setFont(new java.awt.Font("Ubuntu",0,12));
	    		selectall.setText("Seleccionar todo");
	    		selectall.setIcon(new ImageIcon(getClass().getResource("selectall.gif")));
	    		selectall.addActionListener(new ActionListener() {
	    			public void actionPerformed(ActionEvent evt) {
	    				selectallActionPerformed(evt);
	    			}
	    		});
	    	}
	    	return selectall;
	    }
	    
	    private void selectallActionPerformed(ActionEvent evt) {
	    	editor.selectAll();
	    	editor.requestFocus();
	    }
	    
	    private void f9pxActionPerformed(ActionEvent evt) {
	    	cmbTamaño.setSelectedIndex(1);
			tags_tamanio();
	    }
	    
	    private void f12pxActionPerformed(ActionEvent evt) {
	    	cmbTamaño.setSelectedIndex(2);
			tags_tamanio();
	    }
	    
	    private void f14pxActionPerformed(ActionEvent evt) {
	    	cmbTamaño.setSelectedIndex(3);
			tags_tamanio();
	    }
	    
	    private void f16pxActionPerformed(ActionEvent evt) {
	    	cmbTamaño.setSelectedIndex(4);
			tags_tamanio();
	    }
	    
	    private void f18pxActionPerformed(ActionEvent evt) {
	    	cmbTamaño.setSelectedIndex(5);
			tags_tamanio();
	    }
	    
	    private void f20pxActionPerformed(ActionEvent evt) {
	    	cmbTamaño.setSelectedIndex(6);
			tags_tamanio();
	    }
	    
	    private void f22pxActionPerformed(ActionEvent evt) {
	    	cmbTamaño.setSelectedIndex(7);
			tags_tamanio();
	    }
	    
	    private void f24pxActionPerformed(ActionEvent evt) {
	    	cmbTamaño.setSelectedIndex(8);
			tags_tamanio();
	    }
	    
	    private JMenuItem getCortar() {
	    	if(cortar == null) {
	    		cortar = new JMenuItem();
	    		cortar.setText("Cortar");
	    		cortar.setFont(new java.awt.Font("Ubuntu",0,12));
	    		cortar.setIcon(new ImageIcon(getClass().getResource(icon_cut)));
	    		cortar.addActionListener(new ActionListener() {
	    			public void actionPerformed(ActionEvent evt) {
	    				cortarActionPerformed(evt);
	    			}
	    		});
	    	}
	    	return cortar;
	    }
	    
	    private void cortarActionPerformed(ActionEvent evt) {
	    	editor.cut();
	    }
	    
	    private JButton getAum_fuen() {
	    	if(aum_fuen == null) {
	    		aum_fuen = new JButton();
	    		aum_fuen.setSize(30, 30);
	    		aum_fuen.setIcon(new ImageIcon(getClass().getResource(icon_zoom_in)));
	    		aum_fuen.setBackground(new java.awt.Color(255,255,255));
	    		aum_fuen.setPreferredSize(new java.awt.Dimension(30, 30));
	    		aum_fuen.setToolTipText("Aumentar la fuente del editor (Ctrl-arriba)");
	    		aum_fuen.setBorderPainted(false);
	    		aum_fuen.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_UP, Event.CTRL_MASK), "play");
	    		aum_fuen.getActionMap().put("play", new AbstractAction() {
				/**
					 * 
					 */
					private static final long serialVersionUID = 1L;

				public void actionPerformed(ActionEvent e) {
					doBiggerFontSizeAction();  // some function
				}
				});
	    		aum_fuen.addActionListener(new ActionListener() {
	    			public void actionPerformed(ActionEvent evt) {
	    				try {
							aum_fuenActionPerformed(evt);
						} catch (BadLocationException e) {
							
							e.printStackTrace();
						}
	    			}
	    		});
	    	}
	    	return aum_fuen;
	    }
	    
	    private JButton getDis_fuen() {
	    	if(dis_fuen == null) {
	    		dis_fuen = new JButton();
	    		dis_fuen.setSize(30, 30);
	    		dis_fuen.setIcon(new ImageIcon(getClass().getResource(icon_zoom_out)));
	    		dis_fuen.setBackground(new java.awt.Color(255,255,255));
	    		dis_fuen.setPreferredSize(new java.awt.Dimension(30, 30));
	    		dis_fuen.setToolTipText("Disminuir la fuente del editor (Ctrl-abajo)");
	    		dis_fuen.setBorderPainted(false);
	    		dis_fuen.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, Event.CTRL_MASK), "play");
				dis_fuen.getActionMap().put("play", new AbstractAction() {
				/**
					 * 
					 */
					private static final long serialVersionUID = 1L;

				public void actionPerformed(ActionEvent e) {
					doSmallerFontSizeAction();  // some function
				}
				});
	    		dis_fuen.addActionListener(new ActionListener() {
	    			public void actionPerformed(ActionEvent evt) {
	    				dis_fuenActionPerformed(evt);
	    			}
	    		});
	    	}
	    	return dis_fuen;
	    }
	    
	    private void aum_fuenActionPerformed(ActionEvent evt) throws BadLocationException {
	    	doBiggerFontSizeAction();
	    	
	    }
	    public void doSmallerFontSizeAction()
	    {
	    	  // get the current font
	    	  Font f = editor.getFont();

	    	  // create a new, smaller font from the current font
	    	  Font f2 = new Font(f.getFontName(), f.getStyle(), f.getSize()-2);

	    	  // set the new font in the editing area
	    	  int a=editor.getCaretPosition();
	    	  editor.setFont(f2);
	    	  editor.requestFocus();
	    	  editor.setCaretPosition(a);
	    	  
	    	  
	    	}
	    
	    public void doBiggerFontSizeAction()
	    {
	    	  // get the current font
	    	  Font f = editor.getFont();
	    	  	    	  // create a new, smaller font from the current font
	    	  Font f2 = new Font(f.getFontName(), f.getStyle(), f.getSize()+2);

	    	  // set the new font in the editing area
	    	  int a=editor.getCaretPosition();
	    	  editor.setFont(f2);
	    	  editor.requestFocus();
	    	  editor.setCaretPosition(a);
	    	}
	    
	    
	    private void dis_fuenActionPerformed(ActionEvent evt) {
	    	doSmallerFontSizeAction();
	    	
	    	
            }

	    private JPanel getJPanel4() {
	    	if(jPanel4 == null) {
	    		jPanel4 = new JPanel();
	    		TableLayout jPanel4Layout = new TableLayout(new double[][] {{7.0, TableLayout.FILL, TableLayout.FILL, TableLayout.FILL, TableLayout.FILL, 7.0}, {12.0, 20.0, 12.0, 20.0}});
	    		jPanel4Layout.setHGap(5);
	    		jPanel4Layout.setVGap(5);
	    		jPanel4.setLayout(jPanel4Layout);
	    		//jPanel4.setBackground(new java.awt.Color(255,255,255));
	    		jPanel4.add(getJLabel1(), "1, 0, 4, 0, c, f");
	    		jPanel4.add(getComboImagenes(), "1, 1, 4, 1");
	    		jPanel4.add(getJLabel6(), "1,2,4,2,c,f");
	       		jPanel4.add(getEstilosLabel(), "1,2,4,2,c,f");
	    		jPanel4.add(getEstilosComboBox(), "1, 3, 4, 3");
	    	}
	    	return jPanel4;
	    }
	    
	    private JLabel getJLabel1() {
	    	if(jLabel1 == null) {
	    		jLabel1 = new JLabel();
	    		jLabel1.setText("Imagenes predefinidas");
	    		jLabel1.setFont(new java.awt.Font("Arial",0,12));
	    	}
	    	return jLabel1;
	    }
	    
	    private JSeparator getJSeparator1() {
	    	if(jSeparator1 == null) {
	    		jSeparator1 = new JSeparator();
	    		jSeparator1.setBounds(143, 85, 70, 8);
	    	}
	    	return jSeparator1;
	    }

	  	    
	    private JButton getCod1() {
	    	if(cod1 == null) {
	    		cod1 = new JButton();
	    		cod1.setIcon(new ImageIcon(getClass().getResource("1-30x30.png")));
	    		cod1.setPreferredSize(new java.awt.Dimension(30,30));
	    		cod1.setSize(30, 30);
	    		cod1.setBorder(BorderFactory.createTitledBorder(""));
	    		cod1.setBorderPainted(false);
	    		cod1.setBackground(new java.awt.Color(255,255,255));
	    		cod1.addActionListener(new ActionListener() {
	    			public void actionPerformed(ActionEvent evt) {
	    				cod1ActionPerformed(evt);
	    			}
	    		});
	    		
	    		cod1.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_1, Event.CTRL_MASK), "play");
	    		cod1.getActionMap().put("play", new AbstractAction() {
				/**
					 * 
					 */
					private static final long serialVersionUID = 1L;

					public void actionPerformed(ActionEvent evt) {
	    				cod1ActionPerformed(evt);
	    			}
	    		});
	    		
	    			
	    		
	    		
	    		
	    	
	    	}
	    	return cod1;
	    }
	    
	    private JButton getCod2() {
	    	if(cod2 == null) {
	    		cod2 = new JButton();
	    		cod2.setIcon(new ImageIcon(getClass().getResource("2-30x30.png")));
	    		cod2.setPreferredSize(new java.awt.Dimension(30,30));
	    		cod2.setSize(30, 30);
	    		cod2.setBorder(BorderFactory.createTitledBorder(""));
	    		cod2.setBorderPainted(false);
	    		cod2.setBackground(new java.awt.Color(255,255,255));
	    		cod2.addActionListener(new ActionListener() {
	    			public void actionPerformed(ActionEvent evt) {
	    				cod2ActionPerformed(evt);
	    			}
	    		});
	    		
	    		cod2.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_2, Event.CTRL_MASK), "play");
	    		cod2.getActionMap().put("play", new AbstractAction() {
				/**
					 * 
					 */
					private static final long serialVersionUID = 1L;

					public void actionPerformed(ActionEvent evt) {
	    				cod2ActionPerformed(evt);
	    			}
	    		});
	    		
	    	}
	    	return cod2;
	    }
	    
	    private JButton getCod3() {
	    	if(cod3 == null) {
	    		cod3 = new JButton();
	    		cod3.setIcon(new ImageIcon(getClass().getResource("3-30x30.png")));
	    		cod3.setPreferredSize(new java.awt.Dimension(30,30));
	    		cod3.setSize(30, 30);
	    		cod3.setBorder(BorderFactory.createTitledBorder(""));
	    		cod3.setBorderPainted(false);
	    		cod3.setBackground(new java.awt.Color(255,255,255));
	    		cod3.addActionListener(new ActionListener() {
	    			public void actionPerformed(ActionEvent evt) {
	    				cod3ActionPerformed(evt);
	    			}
	    		});
	    		
	    		cod3.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_3, Event.CTRL_MASK), "play");
	    		cod3.getActionMap().put("play", new AbstractAction() {
				/**
					 * 
					 */
					private static final long serialVersionUID = 1L;

					public void actionPerformed(ActionEvent evt) {
	    				cod3ActionPerformed(evt);
	    			}
	    		});
	    		
	    	}
	    	return cod3;
	    }
	    
	    private JButton getCod4() {
	    	if(cod4 == null) {
	    		cod4 = new JButton();
	    		cod4.setIcon(new ImageIcon(getClass().getResource("4-30x30.png")));
	    		cod4.setPreferredSize(new java.awt.Dimension(30,30));
	    		cod4.setSize(30, 30);
	    		cod4.setBorder(BorderFactory.createTitledBorder(""));
	    		cod4.setBorderPainted(false);
	    		cod4.setBackground(new java.awt.Color(255,255,255));
	    		cod4.addActionListener(new ActionListener() {
	    			public void actionPerformed(ActionEvent evt) {
	    				cod4ActionPerformed(evt);
	    			}
	    		});
	    		
	    		cod4.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_4, Event.CTRL_MASK), "play");
	    		cod4.getActionMap().put("play", new AbstractAction() {
				/**
					 * 
					 */
					private static final long serialVersionUID = 1L;

					public void actionPerformed(ActionEvent evt) {
	    				cod4ActionPerformed(evt);
	    			}
	    		});
	    		
	    	}
	    	return cod4;
	    }
	    
	    private JLabel getJLabel2() {
	    	if(jLabel2 == null) {
	    		jLabel2 = new JLabel();
	    		jLabel2.setText("Codigos predefinidos");
	    		jLabel2.setFont(new java.awt.Font("Arial",0,12));
	    	}
	    	return jLabel2;
	    }
	    
	    private JToggleButton getToggle() {
	    	if(toggle == null) {
	    		toggle = new JToggleButton();
	    		toggle.setText("Guardar");
	    		toggle.setFont(fuenteBoton);
	    		toggle.setPreferredSize(new java.awt.Dimension(90, 12));
	    		toggle.addActionListener(new ActionListener() {
	    			public void actionPerformed(ActionEvent evt) {
	    				toggleActionPerformed(evt);
	    			}
	    		});
	    	}
	    	return toggle;
	    }
	    
	    private void cod1ActionPerformed(ActionEvent evt) {
	    	int i;
	    	
	    	if (toggle.isSelected()) {
	    		
	    		
	    		i=JOptionPane.showConfirmDialog(this,"¿Guardamos?","Guardar codigo",JOptionPane.YES_NO_OPTION);
			if(i==0){
				if (editor.getSelectedText()==null) config.guardarCod(editor.getText(),1);
				else config.guardarCod(editor.getSelectedText(),1);
				}
				toggle.setSelected(false);
				cod1.setToolTipText("<html>"+bbcode.convertir(config.cargarCod(1))+"</html>");
			}
	    	
	    	 else
	    		 
	    	 {
	    		 if (borrar.isSelected()) {
	    			 i=JOptionPane.showConfirmDialog(this,"¿Borramos?","Borrar codigo",JOptionPane.YES_NO_OPTION);
	    				if(i==0){ config.guardarCod("",1);
	    				cod1.setToolTipText("");
	    				}
	    				borrar.setSelected(false);
	    				
	    				}
	    		 else
	    		 editor.replaceSelection(config.cargarCod(1));
	    	 }
	    	
	    	
	    	toggle.setSelected(false);
	    	editor.requestFocus();
	    }
	    
	    private void cod2ActionPerformed(ActionEvent evt) {
	    	int i;
	    	if (toggle.isSelected()) {
	    		
	    		
	    		i=JOptionPane.showConfirmDialog(this,"¿Guardamos?","Guardar codigo",JOptionPane.YES_NO_OPTION);
			if(i==0){
				if (editor.getSelectedText()==null) config.guardarCod(editor.getText(),2);
				else config.guardarCod(editor.getSelectedText(),2);}
				toggle.setSelected(false);
				cod2.setToolTipText("<html>"+bbcode.convertir(config.cargarCod(2))+"</html>");
			}
	    	
	    	 else
	    		 
	    	 {
	    		 if (borrar.isSelected()) {
	    			 i=JOptionPane.showConfirmDialog(this,"¿Borramos?","Borrar codigo",JOptionPane.YES_NO_OPTION);
	    				if(i==0){ config.guardarCod("",2);
	    				cod2.setToolTipText("");
	    				}
	    				borrar.setSelected(false);
	    				
	    				}
	    		 else
	    		 editor.replaceSelection(config.cargarCod(2));
	    	 }
	    	
	    	
	    	toggle.setSelected(false);
	    	editor.requestFocus();
	    }
	    
	    private void cod3ActionPerformed(ActionEvent evt) {
	    	int i;
	    	if (toggle.isSelected()) {
	    		
	    		
	    		i=JOptionPane.showConfirmDialog(this,"¿Guardamos?","Guardar codigo",JOptionPane.YES_NO_OPTION);
	    		if(i==0){
					if (editor.getSelectedText()==null) config.guardarCod(editor.getText(),3);
					else config.guardarCod(editor.getSelectedText(),3);}
				toggle.setSelected(false);
				cod3.setToolTipText("<html>"+bbcode.convertir(config.cargarCod(3))+"</html>");
			}
	    	
	    	 else
	    		 
	    	 {
	    		 if (borrar.isSelected()) {
	    			 i=JOptionPane.showConfirmDialog(this,"¿Borramos?","Borrar codigo",JOptionPane.YES_NO_OPTION);
	    				if(i==0){ config.guardarCod("",3);
	    				cod3.setToolTipText("");
	    				}
	    				borrar.setSelected(false);
	    				
	    				
	    				}
	    		 else
	    		 editor.replaceSelection(config.cargarCod(3));
	    	 }
	    	
	    	
	    	toggle.setSelected(false);
	    	editor.requestFocus();
	    }
	    
	    private void cod4ActionPerformed(ActionEvent evt) {
	    	int i;
	    	if (toggle.isSelected()) {
	    		
	    		
	    		i=JOptionPane.showConfirmDialog(this,"¿Guardamos?","Guardar codigo",JOptionPane.YES_NO_OPTION);
	    		if(i==0){
					if (editor.getSelectedText()==null) config.guardarCod(editor.getText(),4);
					else config.guardarCod(editor.getSelectedText(),4);}
				toggle.setSelected(false);
				cod4.setToolTipText("<html>"+bbcode.convertir(config.cargarCod(4))+"</html>");
			}
	    	
	    	 else
	    		 
	    	 {
	    		 if (borrar.isSelected()) {
	    			 i=JOptionPane.showConfirmDialog(this,"¿Borramos?","Borrar codigo",JOptionPane.YES_NO_OPTION);
	    				if(i==0){ config.guardarCod("",4);
	    				cod4.setToolTipText("");
	    				}
	    				borrar.setSelected(false);
	    				}
	    		 else
	    		 editor.replaceSelection(config.cargarCod(4));
	    	 }
	    	
	    	
	    	toggle.setSelected(false);
	    	editor.requestFocus();
	    }
	    
	    private JToggleButton getBorrar() {
	    	if(borrar == null) {
	    		borrar = new JToggleButton();
	    		borrar.setText(" Borrar ");
	    		borrar.setFont(fuenteBoton);
	    		borrar.setSize(70, 25);
	    		borrar.setPreferredSize(new java.awt.Dimension(90, 12));
	    		borrar.addActionListener(new ActionListener() {
	    			public void actionPerformed(ActionEvent evt) {
	    				borrarActionPerformed(evt);
	    			}
	    		});
	    	}
	    	return borrar;
	    }
	    
	    private void toggleActionPerformed(ActionEvent evt) {
	    	if (borrar.isSelected()) borrar.setSelected(false);
	    }
	    
	    private void borrarActionPerformed(ActionEvent evt) {
	    	if (toggle.isSelected()) toggle.setSelected(false);
	    }
	    
	    private JButton getBliptv() {
	    	if(bliptv == null) {
	    		bliptv = new JButton();
	    		bliptv.setPreferredSize(new java.awt.Dimension(30, 30));
	    		bliptv.setSize(30, 30);
	    		bliptv.setIcon(new ImageIcon(getClass().getResource("bliptv.png")));
	    		bliptv.setToolTipText("Insertar video de Blip.tv");
	    		bliptv.setBorderPainted(false);
	    		
	    		bliptv.addActionListener(new ActionListener() {
	    			public void actionPerformed(ActionEvent evt) {
	    				bliptvActionPerformed(evt);
	    			}
	    		});
	    	}
	    	return bliptv;
	    }
	    
	    private void bliptvActionPerformed(ActionEvent evt) {
	    	String seleccion=editor.getSelectedText();
			if (!(dialogo.isVisible() | (dialogo2.isVisible()))) {
				if (seleccion != null) 
					if (Analizador.esBliptv(seleccion)) generarBliptv(seleccion,true);
					else
					{
						dialogo.setTipo("bliptv");
						dialogo.setTitle("Insertar video desde Blip.tv");
						dialogo.cambiarLabel("Ingresa el codigo embebido del video");
						dialogo.setVisible(true);
					}
				else
			{
				dialogo.setTipo("bliptv");
				dialogo.setTitle("Insertar video desde Blip.tv");
				dialogo.cambiarLabel("Ingresa el codigo embebido del video");
				dialogo.setVisible(true);
			}
		}
			dialogo.obtenerFoco();
	    }

	    private void PopCortar1ActionPerformed(ActionEvent evt) {
	    	if (popup1.getInvoker().getName()=="titulo")
	    	{
	    		titulo.cut();
	    		titulo.requestFocus();
	    	}
	    		else
	    		{
	    			jTags.cut();
	    		jTags.requestFocus();
	    		}
	    	
		}
	    
	    
	    private void PopPegar1ActionPerformed(ActionEvent evt) {
	    	if (popup1.getInvoker().getName()=="titulo")
	    	{	
	    		if (titulo.getText().equals(tituloDefault))	{
	    			titulo.setText("");
	    			titulo.setFont(new java.awt.Font("DejaVu Sans",0,12));
	    			
	    		}
	    		
	    		titulo.paste();
	    		titulo.requestFocus();
	    		    	}
	    	else
	    	{
	    		if (jTags.getText().equals(tagsDefault)){
	    			jTags.setText("");
	    			jTags.setFont(new java.awt.Font("DejaVu Sans",0,12));
	    		}
	    	
	    		jTags.paste();
	    		jTags.requestFocus();
	    	}
	    }
	    
	    private void PopCopiar1ActionPerformed(ActionEvent evt) {
	    	if (popup1.getInvoker().getName()=="titulo")
	    	{	
	    		titulo.copy();
	    		    	}
	    	else
	    	{ 
	    		jTags.copy();
	    	}
	    }
	    
	    
	    
	    private void PopSelAll1ActionPerformed(ActionEvent evt) {
	    	if (popup1.getInvoker().getName()=="titulo"){
	    			    	titulo.selectAll(); 
	    			    	titulo.requestFocus();		    	
	    	}
	    	else {
	    		
	    		jTags.selectAll();
	    		jTags.requestFocus();
	    	}
		}
	    
	   
	    
	    private JPanel getEmoticons() {
	    	if(emoticons == null) {
	    		emoticons = new JPanel();
	    	//	emoticons.setBackground(new java.awt.Color(255,255,255));
	    		emoticons.add(getAum_fuen());
	    		emoticons.add(getDis_fuen());
	    		emoticons.add(getEmo1());
	    		emoticons.add(getEmo2());
	    		emoticons.add(getEmo3());
	    		emoticons.add(getEmo4());
	    		emoticons.add(getEmo5());
	    		emoticons.add(getEmo6());
	    		emoticons.add(getEmo7());
	    		emoticons.add(getEmo8());
	    		emoticons.add(getEmo9());
	    		emoticons.add(getEmo10());
	    		emoticons.add(getEmo11());
	    		emoticons.add(getEmo12());
	    		emoticons.add(getEmo13());
	    		emoticons.add(getEmo14());
	    		emoticons.add(getEmo15());
	    		emoticons.add(getEmo16());
	    		emoticons.add(getPlus_emo());
	    		emoticons.add(getCat());
	    		emoticons.add(getJComboBox1());
	    		emoticons.add(getJComboBox2());
	    		emoticons.add(getReloadComu());
	    		emoticons.add(getJComboBox3());
	    	}
	    	return emoticons;
	    }
	    
	   
	    
	    private JButton getEmo1() {
	    	if(emo1 == null) {
	    		emo1 = new JButton();
	    		emo1.setPreferredSize(new java.awt.Dimension(16,16));
				emo1.setSize(16, 16);
				emo1.setBorderPainted(false);
	    		emo1.setIcon(new ImageIcon(getClass().getResource("emo1.gif")));
	    		emo1.setBackground(new java.awt.Color(255,255,255));
	    		emo1.addActionListener(new ActionListener() {
	    			public void actionPerformed(ActionEvent evt) {
	    				emo1ActionPerformed(evt);
	    			}
	    		});
	    	}
	    	return emo1;
	    }

	    private JButton getEmo2() {
	    	if(emo2 == null) {
	    		emo2 = new JButton();
	    		emo2.setPreferredSize(new java.awt.Dimension(16,16));
				emo2.setSize(16, 16);
				emo2.setBorderPainted(false);
	    		emo2.setIcon(new ImageIcon(getClass().getResource("emo19.gif")));
	    		emo2.setBackground(new java.awt.Color(255,255,255));
	    		emo2.addActionListener(new ActionListener() {
	    			public void actionPerformed(ActionEvent evt) {
	    				emo2ActionPerformed(evt);
	    			}
	    		});
	    	}
	    	return emo2;
	    }
	    
	    private JButton getEmo3() {
	    	if(emo3 == null) {
	    		emo3 = new JButton();
	    		emo3.setPreferredSize(new java.awt.Dimension(16,16));
	    		emo3.setSize(16, 16);
	    		emo3.setBorderPainted(false);
	    		emo3.setIcon(new ImageIcon(getClass().getResource("emo18.gif")));
	    		emo3.setBackground(new java.awt.Color(255,255,255));
	    		emo3.addActionListener(new ActionListener() {
	    			public void actionPerformed(ActionEvent evt) {
	    				emo3ActionPerformed(evt);
	    			}
	    		});
	    	}
	    	return emo3;
	    }
	    
	    private JButton getEmo4() {
	    	if(emo4 == null) {
	    		emo4 = new JButton();
	    		emo4.setPreferredSize(new java.awt.Dimension(16,16));
	    		emo4.setSize(16, 16);
	    		emo4.setBorderPainted(false);
	    		emo4.setIcon(new ImageIcon(getClass().getResource("emo17.gif")));
	    		emo4.setBackground(new java.awt.Color(255,255,255));
	    		emo4.addActionListener(new ActionListener() {
	    			public void actionPerformed(ActionEvent evt) {
	    				emo4ActionPerformed(evt);
	    			}
	    		});
	    	}
	    	return emo4;
	    }
	    
	    private JButton getEmo5() {
	    	if(emo5 == null) {
	    		emo5 = new JButton();
	    		emo5.setPreferredSize(new java.awt.Dimension(16,16));
	    		emo5.setSize(16, 16);
	    		emo5.setBorderPainted(false);
	    		emo5.setIcon(new ImageIcon(getClass().getResource("emo12.gif")));
	    		emo5.setBackground(new java.awt.Color(255,255,255));
	    		emo5.addActionListener(new ActionListener() {
	    			public void actionPerformed(ActionEvent evt) {
	    				emo5ActionPerformed(evt);
	    			}
	    		});
	    	}
	    	return emo5;
	    }
	    
	    private JButton getEmo6() {
	    	if(emo6 == null) {
	    		emo6 = new JButton();
	    		emo6.setPreferredSize(new java.awt.Dimension(16,16));
	    		emo6.setSize(16, 16);
	    		emo6.setBorderPainted(false);
	    		emo6.setIcon(new ImageIcon(getClass().getResource("emo4.gif")));
	    		emo6.setBackground(new java.awt.Color(255,255,255));
	    		emo6.addActionListener(new ActionListener() {
	    			public void actionPerformed(ActionEvent evt) {
	    				emo6ActionPerformed(evt);
	    			}
	    		});
	    	}
	    	return emo6;
	    }
	    
	    private JButton getEmo7() {
	    	if(emo7 == null) {
	    		emo7 = new JButton();
	    		emo7.setPreferredSize(new java.awt.Dimension(16,16));
	    		emo7.setSize(16, 16);
	    		emo7.setBorderPainted(false);
	    		emo7.setIcon(new ImageIcon(getClass().getResource("emo2.gif")));
	    		emo7.setBackground(new java.awt.Color(255,255,255));
	    		emo7.addActionListener(new ActionListener() {
	    			public void actionPerformed(ActionEvent evt) {
	    				emo7ActionPerformed(evt);
	    			}
	    		});
	    	}
	    	return emo7;
	    }
	    
	    private JButton getEmo8() {
	    	if(emo8 == null) {
	    		emo8 = new JButton();
	    		emo8.setPreferredSize(new java.awt.Dimension(16,16));
	    		emo8.setSize(16, 16);
	    		emo8.setBorderPainted(false);
	    		emo8.setIcon(new ImageIcon(getClass().getResource("emo16.gif")));
	    		emo8.setBackground(new java.awt.Color(255,255,255));
	    		emo8.addActionListener(new ActionListener() {
	    			public void actionPerformed(ActionEvent evt) {
	    				emo8ActionPerformed(evt);
	    			}
	    		});
	    	}
	    	return emo8;
	    }
	    
	    private JButton getEmo9() {
	    	if(emo9 == null) {
	    		emo9 = new JButton();
	    		emo9.setPreferredSize(new java.awt.Dimension(16,16));
	    		emo9.setSize(16, 16);
	    		emo9.setBorderPainted(false);
	    		emo9.setIcon(new ImageIcon(getClass().getResource("emo9.gif")));
	    		emo9.setBackground(new java.awt.Color(255,255,255));
	    		emo9.addActionListener(new ActionListener() {
	    			public void actionPerformed(ActionEvent evt) {
	    				emo9ActionPerformed(evt);
	    			}
	    		});
	    	}
	    	return emo9;
	    }
	    
	    private JButton getEmo10() {
	    	if(emo10 == null) {
	    		emo10 = new JButton();
	    		emo10.setPreferredSize(new java.awt.Dimension(16,16));
	    		emo10.setSize(16, 16);
	    		emo10.setBorderPainted(false);
	    		emo10.setIcon(new ImageIcon(getClass().getResource("emo11.gif")));
	    		emo10.setBackground(new java.awt.Color(255,255,255));
	    		emo10.addActionListener(new ActionListener() {
	    			public void actionPerformed(ActionEvent evt) {
	    				emo10ActionPerformed(evt);
	    			}
	    		});
	    	}
	    	return emo10;
	    }
	    
	    private JButton getEmo11() {
	    	if(emo11 == null) {
	    		emo11 = new JButton();
	    		emo11.setPreferredSize(new java.awt.Dimension(16,16));
	    		emo11.setSize(16, 16);
	    		emo11.setBorderPainted(false);
	    		emo11.setIcon(new ImageIcon(getClass().getResource("emo14.gif")));
	    		emo11.setBackground(new java.awt.Color(255,255,255));
	    		emo11.addActionListener(new ActionListener() {
	    			public void actionPerformed(ActionEvent evt) {
	    				emo11ActionPerformed(evt);
	    			}
	    		});
	    	}
	    	return emo11;
	    }
	    
	    private JButton getEmo12() {
	    	if(emo12 == null) {
	    		emo12 = new JButton();
	    		emo12.setPreferredSize(new java.awt.Dimension(16,16));
	    		emo12.setSize(16, 16);
	    		emo12.setBorderPainted(false);
	    		emo12.setIcon(new ImageIcon(getClass().getResource("emo3.gif")));
	    		emo12.setBackground(new java.awt.Color(255,255,255));
	    		emo12.addActionListener(new ActionListener() {
	    			public void actionPerformed(ActionEvent evt) {
	    				emo12ActionPerformed(evt);
	    			}
	    		});
	    	}
	    	return emo12;
	    }
	    
	    private JButton getEmo13() {
	    	if(emo13 == null) {
	    		emo13 = new JButton();
	    		emo13.setPreferredSize(new java.awt.Dimension(16,16));
	    		emo13.setSize(16, 16);
	    		emo13.setBorderPainted(false);
	    		emo13.setIcon(new ImageIcon(getClass().getResource("emo13.gif")));
	    		emo13.setBackground(new java.awt.Color(255,255,255));
	    		emo13.addActionListener(new ActionListener() {
	    			public void actionPerformed(ActionEvent evt) {
	    				emo13ActionPerformed(evt);
	    			}
	    		});
	    	}
	    	return emo13;
	    }
	    
	    private JButton getEmo14() {
	    	if(emo14 == null) {
	    		emo14 = new JButton();
	    		emo14.setPreferredSize(new java.awt.Dimension(16,16));
	    		emo14.setSize(16, 16);
	    		emo14.setBorderPainted(false);
	    		emo14.setIcon(new ImageIcon(getClass().getResource("emo10.gif")));
	    		emo14.setBackground(new java.awt.Color(255,255,255));
	    		emo14.addActionListener(new ActionListener() {
	    			public void actionPerformed(ActionEvent evt) {
	    				emo14ActionPerformed(evt);
	    			}
	    		});
	    	}
	    	return emo14;
	    }
	    
	    private JButton getEmo15() {
	    	if(emo15 == null) {
	    		emo15 = new JButton();
	    		emo15.setPreferredSize(new java.awt.Dimension(16,16));
	    		emo15.setSize(16, 16);
	    		emo15.setBorderPainted(false);
	    		emo15.setIcon(new ImageIcon(getClass().getResource("emo0.gif")));
	    		emo15.setBackground(new java.awt.Color(255,255,255));
	    		emo15.addActionListener(new ActionListener() {
	    			public void actionPerformed(ActionEvent evt) {
	    				emo15ActionPerformed(evt);
	    			}
	    		});
	    	}
	    	return emo15;
	    }
	    
	    private JButton getEmo16() {
	    	if(emo16 == null) {
	    		emo16 = new JButton();
	    		emo16.setPreferredSize(new java.awt.Dimension(16,16));
	    		emo16.setSize(16, 16);
	    		emo16.setBorderPainted(false);
	    		emo16.setIcon(new ImageIcon(getClass().getResource("emo15.gif")));
	    		emo16.setBackground(new java.awt.Color(255,255,255));
	    		emo16.addActionListener(new ActionListener() {
	    			public void actionPerformed(ActionEvent evt) {
	    				emo16ActionPerformed(evt);
	    			}
	    		});
	    	}
	    	return emo16;
	    }
	    
	    
	    public void insertar_emo(int i){
	    	switch(i){
	    	
	    	case 0:editor.replaceSelection("8| ");break;
	    	case 1:editor.replaceSelection(":) ");break;
	    	case 2:editor.replaceSelection("X( ");break;
	    	case 3:editor.replaceSelection(":cool: ");break;
	    	case 4:editor.replaceSelection(":cry: ");break;
	    	case 5:editor.replaceSelection(":/ ");break;
	    	case 6:editor.replaceSelection(":blaf ");break;
	    	case 7:editor.replaceSelection(":winky: ");break;
	    	case 8:editor.replaceSelection(":noo: ");  break;
	    	case 9:editor.replaceSelection(":twisted: ");break;
	    	case 10:editor.replaceSelection("^^ ");break;
	    	case 11:editor.replaceSelection(":| "); break;
	    	case 12:editor.replaceSelection(":D "); break;
	    	case 13:editor.replaceSelection(":oops: ");break;
	    	case 14:editor.replaceSelection(":? ");break;
	    	case 15:editor.replaceSelection(":F "); break;
	    	case 16:editor.replaceSelection(":( "); break;
	    	case 17:editor.replaceSelection(":P "); break;
	    	case 18:editor.replaceSelection(":roll: "); break;
	    	case 19:editor.replaceSelection(";) "); break;
	    	case 20:editor.replaceSelection(":crying: "); break;
	    	case 21:editor.replaceSelection(":bobo: "); break;
	    	case 22:editor.replaceSelection(":grin: "); break;
	    	case 23:editor.replaceSelection(":alaba: "); break;
	    	case 24:editor.replaceSelection(":lpmqtp: "); break;
	    	case 25:editor.replaceSelection(":idiot: "); break;
	    	case 26:editor.replaceSelection(":shrug: "); break;
	    	case 27:editor.replaceSelection(":8S: "); break;
	    	case 28:editor.replaceSelection(":] "); break;
	    	case 29:editor.replaceSelection(":blind: "); break;
	    	case 30:editor.replaceSelection(":buaa: "); break;
	    	case 31:editor.replaceSelection(":cold: "); break;
	    	case 32:editor.replaceSelection(":hot: "); break;
	    	case 33:editor.replaceSelection(":love: "); break;
	    	case 34:editor.replaceSelection(":globo: "); break;
	    	case 35:editor.replaceSelection(":zombie: "); break;
	    	case 36:editor.replaceSelection(":man: "); break;
	    	case 37:editor.replaceSelection(":metal: "); break;
	    	case 38:editor.replaceSelection(":mario: "); break;
	    	case 39:editor.replaceSelection(":info: "); break;
	    	case 40:editor.replaceSelection(":exc: "); break;
	    	case 41:editor.replaceSelection(":q: "); break;
	    	case 42:editor.replaceSelection(":NO: "); break;
	    	case 43:editor.replaceSelection(":OK: "); break;
	    	case 44:editor.replaceSelection(":WOW: "); break;
	    	case 45:editor.replaceSelection(":LOL: "); break;
	    	case 46:editor.replaceSelection(":oo: "); break;
	    	case 47:editor.replaceSelection(":RIP: "); break;
	    	case 48:editor.replaceSelection(":alien: "); break;
	    	case 49:editor.replaceSelection(":trago: "); break;
	    	case 50:editor.replaceSelection(":money: "); break;
	    	case 51:editor.replaceSelection(":culo: "); break;
	    	case 52:editor.replaceSelection(":auto: "); break;
	    	case 53:editor.replaceSelection(":lala: "); break;
	    	case 54:editor.replaceSelection(":fantasma: "); break;
	    	case 55:editor.replaceSelection(":buenpost: "); break;
	    	case 56:editor.replaceSelection(":GET A LIFE: "); break;
	    	case 57:editor.replaceSelection(":headbang: "); break;
	    	case 58:editor.replaceSelection(":limon: "); break;
	    	case 59:editor.replaceSelection(":verde: "); break;
	    		
	    		
	    	
	    		
	    	}
	    		
	    }
	    
	    
	    
	    private JButton getPlus_emo() {
	    	if(plus_emo == null) {
	    		plus_emo = new JButton();
	    		plus_emo.setPreferredSize(new java.awt.Dimension(121, 25));
	    		plus_emo.setSize(16, 16);
	    		plus_emo.setBorderPainted(false);
	    		plus_emo.setIcon(new ImageIcon(getClass().getResource("mas_emo.gif")));
	    	//	plus_emo.setBackground(new java.awt.Color(255,255,255));
	    		plus_emo.setText("emoticones");
	    		plus_emo.setFont(new java.awt.Font("Ubuntu",0,12));
	    		plus_emo.addActionListener(new ActionListener() {
	    			public void actionPerformed(ActionEvent evt) {
	    				plus_emoActionPerformed(evt);
	    			}
	    		});
	    	}
	    	return plus_emo;
	    }
	    
	    private void emo1ActionPerformed(ActionEvent evt) {
	    	insertar_emo(1);
	    	editor.requestFocus();
	    }
	    
	    private void emo2ActionPerformed(ActionEvent evt) {
	    	insertar_emo(19);
	    	editor.requestFocus();
	    }
	    
	    private void emo3ActionPerformed(ActionEvent evt) {
	    	insertar_emo(18);
	    	editor.requestFocus();
	    }
	    
	    private void emo4ActionPerformed(ActionEvent evt) {
	    	insertar_emo(17);
	    	editor.requestFocus();
	    }
	    
	    private void emo5ActionPerformed(ActionEvent evt) {
	    	insertar_emo(12);
	    	editor.requestFocus();
	    }
	    
	    private void emo6ActionPerformed(ActionEvent evt) {
	    	insertar_emo(16);
	    	editor.requestFocus();
	    }
	    
	    private void emo7ActionPerformed(ActionEvent evt) {
	    	insertar_emo(2);
	    	editor.requestFocus();
	    }
	    
	    private void emo8ActionPerformed(ActionEvent evt) {
	    	insertar_emo(4);
	    	editor.requestFocus();
	    }
	    
	    private void emo9ActionPerformed(ActionEvent evt) {
	    	insertar_emo(9);
	    	editor.requestFocus();
	    }
	    
	    private void emo10ActionPerformed(ActionEvent evt) {
	    	insertar_emo(11);
	    	editor.requestFocus();
	    }
	    
	    private void emo11ActionPerformed(ActionEvent evt) {
	    	insertar_emo(14);
	    	editor.requestFocus();
	    }
	    
	    private void emo12ActionPerformed(ActionEvent evt) {
	    	insertar_emo(3);
	    	editor.requestFocus();
	    }
	    
	    private void emo13ActionPerformed(ActionEvent evt) {
	    	insertar_emo(13);
	    	editor.requestFocus();
	    	}
	    
	    private void emo14ActionPerformed(ActionEvent evt) {
	    	insertar_emo(10);
	    	editor.requestFocus();
	    	}
	    
	    private void emo15ActionPerformed(ActionEvent evt) {
	    	insertar_emo(0);
	    	editor.requestFocus();
	    	}
	    
	    private void emo16ActionPerformed(ActionEvent evt) {
	    	insertar_emo(15);
	    	editor.requestFocus();
	    	}
	    
	    private JButton getVimeo() {
	    	if(vimeo == null) {
	    		vimeo = new JButton();
	    		vimeo.setPreferredSize(new java.awt.Dimension(30, 30));
	    		vimeo.setSize(30, 30);
	    		vimeo.setIcon(new ImageIcon(getClass().getResource("vimeo.png")));
	    		vimeo.setToolTipText("Insertar video de Vimeo");
	    		vimeo.setBorderPainted(false);
	    		vimeo.addActionListener(new ActionListener() {
	    			public void actionPerformed(ActionEvent evt) {
	    				vimeoActionPerformed(evt);
	    			}
	    		});
	    	}
	    	return vimeo;
	    }
	    
	   
	    
	    private void plus_emoActionPerformed(ActionEvent evt) {
	    	if (emos==null) {
	    		emos = new Emoticones();
	    		emos.setLocationRelativeTo(null);
	    	emos.conectar(this);
	    	}
	    	emos.setVisible(true);
	    	
	    }
	    
	    
	    private JButton getPreview() {
	    	if(preview == null) {
	    		preview = new JButton(new ImageIcon(Main.class.getResource("preview2.png")));
	    		preview.setText("Previsualizar");
	    		preview.setToolTipText("Previsualizar post en el navegador");
	    		preview.setFont(fuenteBoton);
	    		preview.addActionListener(new ActionListener() {
	    			public void actionPerformed(ActionEvent evt) {
	    				previewActionPerformed(evt);
	    			}
	    		});
	    	}
	    	return preview;
	    }
	    
	    
	   
	    
	    private void previewActionPerformed(ActionEvent evt) {
	    				try {
	    					if (prevOnline.isSelected()) {
		    					if (login(config.getUsuario(),config.getContrasenia()))	previsualizar(preview(),true);
	    					}

	    					else {
	    						System.out.println("Previsualizacion offline");
	    						previsualizar(editor.getText(),false);
	    					}
						} catch (Exception e) {
							JOptionPane.showMessageDialog( Main.this,"No se pudo establecer la conexión con el servidor.\n Chequea tu conexión a internet","Ups", JOptionPane.ERROR_MESSAGE );
							e.printStackTrace();
						}
	    				
	    				
	    				
	    	
	    }
	    
	    
	    private void checkFolder(String folder) {
	    	 File file=new File(folder);
	    			  boolean exists = file.exists();
	    			  if (!exists) { //no existe creo el directorio
	    			 
	    				  if (file.mkdir()) System.out.println("No existia el directorio");
	    			  
	    			  }
	    }
	    
	    
	    public void previsualizar(String str,boolean online) {
	    	browser=config.getBrowser();
	    	String sFichero = path+"post.html";
	    	String encabezado=null;
	    	
	    	try {
	    		checkFolder(path);
	    		Writer out = new OutputStreamWriter(new FileOutputStream(sFichero), "UTF-8");
				if (titulo.getText().equals(tituloDefault)) encabezado=""; else encabezado=truncate(titulo.getText(),60);
				
				if (online) {
					out.write(bbcode.procesar(str,encabezado,true));
				
				}
				else {
				out.write(bbcode.procesar(str,encabezado,false));
				
				}
				out.close();
				
				if (!browser.equals("")) { //hay navegador configurado
					
					Process miProceso;
					if (!config.esLinux()) miProceso = Runtime.getRuntime().exec(browser+" "+"\""+sFichero+"\""); //es windows
					    
					else miProceso = Runtime.getRuntime().exec(browser+" "+sFichero); //es linux
				}
				else 
					java.awt.Desktop.getDesktop().open(new File(sFichero));
				
			} catch (IOException e) {
				
					
					JOptionPane.showMessageDialog(null,"Se produjo un error al ejecutar el navegador. Asegurate que esté bien configurado\nPodes configurarlo desde Menu->Preferencias->Navegador", "Error", JOptionPane.ERROR_MESSAGE);
				} 
	    	
					
				    		
			
	    }

	    private JButton getBugs() {
	    	if(bugs == null) {
	    		bugs = new JButton();
	    		bugs.setText("Reportar un bug");
	    		//bugs.setBackground(new java.awt.Color(255,255,255));
	    		bugs.setFont(new java.awt.Font("Arial",0,10));
	    		bugs.setIcon(new ImageIcon(getClass().getResource("bug.png")));
	    		bugs.setBorderPainted(false);
	    		bugs.setForeground(new java.awt.Color(0,0,255));
	    		bugs.addActionListener(new ActionListener() {
	    			public void actionPerformed(ActionEvent evt) {
	    				bugsActionPerformed(evt);
	    			}
	    		});
	    	}
	    	return bugs;
	    }
	    
	    
	    private void irAbuscador(String contenido) {
	    	if (!config.getBrowser().equals("")) { 
	    		browser=config.getBrowser();
	    		
	    		@SuppressWarnings("unused")
				Process miProceso;
				
					try {
						
						miProceso = Runtime.getRuntime().exec(browser+" "+"http://buscar.taringa.net/posts?engine=taringa&q="+encode(contenido)+"&en=todo");
							    		
						
					} catch (IOException e) {
						try {
							java.awt.Desktop.getDesktop().browse(java.net.URI.create("http://buscar.taringa.net/posts?engine=taringa&q="+encode(contenido)+"&en=todo"));
						} catch (IOException e1) {
							JOptionPane.showMessageDialog(null,e1.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
						}
						
						
					}

	    		
	    		
	    	} else
				try {
					java.awt.Desktop.getDesktop().browse(java.net.URI.create("http://buscar.taringa.net/posts?engine=taringa&q="+encode(contenido)+"&en=todo"));
				} catch (IOException e) {
					JOptionPane.showMessageDialog(null,"No se configuro ningun navegador.Configuralo desde Menu-Configurar Navegador", "Error", JOptionPane.ERROR_MESSAGE);
				}
	    	    	
	    	
	    }
	    
	    
	    
	    
	    
	    private void abrirWeb(String web) {
	    	if (!config.getBrowser().equals("")) { 
	    		browser=config.getBrowser();
	    		
	    		@SuppressWarnings("unused")
				Process miProceso;
				
					try {
						
						miProceso = Runtime.getRuntime().exec(browser+" "+web);
							    		
						
					} catch (IOException e) {
						try {
							java.awt.Desktop.getDesktop().browse(java.net.URI.create(web));
						} catch (IOException e1) {
							JOptionPane.showMessageDialog(null,e1.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
						}
						
						
					}

	    		
	    		
	    	} else
				try {
					java.awt.Desktop.getDesktop().browse(java.net.URI.create(web));
				} catch (IOException e) {
					JOptionPane.showMessageDialog(null,"No se configuro ningun navegador.Configuralo desde Menu-Configurar Navegador", "Error", JOptionPane.ERROR_MESSAGE);
				}
	    	
	    	
	    }
	    
	    private void bugsActionPerformed(ActionEvent evt) {
	    //irAcomunidad();
	    	
		    if (bugReport==null) bugReport = new ReportarBug(this);
		    bugReport.setLocationRelativeTo(this);
		    bugReport.setVisible(true);
		    
		
	    	
	    }
	    
	    private JMenu getEdicion() {
	    	if(edicion == null) {
	    		edicion = new JMenu();
	    		edicion.setText("Edicion");
	    		edicion.setFont(arialPlain12);
	    	//	edicion.setBackground(new java.awt.Color(255,255,255));
	    	//	edicion.setForeground(new java.awt.Color(0,0,0));
	    		edicion.add(getBuscar());
	    		edicion.add(getJSeparator4());
	    		edicion.add(getDeshacer());
	    		edicion.add(getRehacer());
	    		edicion.add(getJSeparator2());
	    		edicion.add(getCopy());
	    		edicion.add(getPaste());
	    		edicion.add(getCut());
	    	}
	    	return edicion;
	    }
	    
	    private JMenuItem getDeshacer() {
	    	if(deshacer == null) {
	    		deshacer = new JMenuItem();
	    		deshacer.setText("Deshacer");
	    	//	deshacer.setBackground(new java.awt.Color(255,255,255));
	    		deshacer.setAccelerator(KeyStroke.getKeyStroke("ctrl pressed Z"));
	    		deshacer.setFont(new java.awt.Font("Arial",0,12));
	    		deshacer.addActionListener(new ActionListener() {
	    			public void actionPerformed(ActionEvent evt) {
	    				deshacerActionPerformed(evt);
	    			}
	    		});
	    	}
	    	return deshacer;
	    }
	    
	    private JMenuItem getRehacer() {
	    	if(rehacer == null) {
	    		rehacer = new JMenuItem();
	    		rehacer.setText("Rehacer");
	    		rehacer.setBounds(71, 21, 64, 23);
	    	//	rehacer.setBackground(new java.awt.Color(255,255,255));
	    		rehacer.setAccelerator(KeyStroke.getKeyStroke("ctrl pressed Y"));
	    		rehacer.setFont(new java.awt.Font("Arial",0,12));
	    		rehacer.addActionListener(new ActionListener() {
	    			public void actionPerformed(ActionEvent evt) {
	    				rehacerActionPerformed(evt);
	    			}
	    		});
	    	}
	    	return rehacer;
	    }
	    
	    private JMenuItem getCopy() {
	    	if(copy == null) {
	    		copy = new JMenuItem();
	    		copy.setText("Copiar");
	    	//	copy.setBackground(new java.awt.Color(255,255,255));
	    		copy.setAccelerator(KeyStroke.getKeyStroke("ctrl pressed C"));
	    		copy.setFont(new java.awt.Font("Arial",0,12));
	    		copy.addActionListener(new ActionListener() {
	    			public void actionPerformed(ActionEvent evt) {
	    				copyActionPerformed(evt);
	    			}
	    		});
	    	}
	    	return copy;
	    }
	    
	    private JMenuItem getPaste() {
	    	if(paste == null) {
	    		paste = new JMenuItem();
	    		paste.setText("Pegar");
	    	//	paste.setBackground(new java.awt.Color(255,255,255));
	    		paste.setAccelerator(KeyStroke.getKeyStroke("ctrl pressed V"));
	    		paste.setFont(new java.awt.Font("Arial",0,12));
	    		paste.addActionListener(new ActionListener() {
	    			public void actionPerformed(ActionEvent evt) {
	    				pasteActionPerformed(evt);
	    			}
	    		});
	    	}
	    	return paste;
	    }
	    
	    private JMenuItem getCut() {
	    	if(cut == null) {
	    		cut = new JMenuItem();
	    		cut.setText("Cortar");
	    	//	cut.setBackground(new java.awt.Color(255,255,255));
	    		cut.setAccelerator(KeyStroke.getKeyStroke("ctrl pressed X"));
	    		cut.setFont(new java.awt.Font("Arial",0,12));
	    		cut.addActionListener(new ActionListener() {
	    			public void actionPerformed(ActionEvent evt) {
	    				cutActionPerformed(evt);
	    			}
	    		});
	    	}
	    	return cut;
	    }
	    
	    private JSeparator getJSeparator2() {
	    	if(jSeparator2 == null) {
	    		jSeparator2 = new JSeparator();
	    		jSeparator2.setBounds(71, 44, 70, 8);
	    	}
	    	return jSeparator2;
	    }
	    
	    private JMenuItem getSelAll() {
	    	if(selAll == null) {
	    		selAll = new JMenuItem();
	    		selAll.setText("Seleccionar todo");
	    	//	selAll.setBackground(new java.awt.Color(255,255,255));
	    		selAll.setAccelerator(KeyStroke.getKeyStroke("ctrl pressed A"));
	    		selAll.setFont(new java.awt.Font("Arial",0,12));
	    		selAll.addActionListener(new ActionListener() {
	    			public void actionPerformed(ActionEvent evt) {
	    				selAllActionPerformed(evt);
	    			}
	    		});
	    	}
	    	return selAll;
	    }
	    
	    private JSeparator getJSeparator3() {
	    	if(jSeparator3 == null) {
	    		jSeparator3 = new JSeparator();
	    		jSeparator3.setBounds(119, 121, 70, 8);
	    	}
	    	return jSeparator3;
	    }
	    
	    private void selAllActionPerformed(ActionEvent evt) {
	    	editor.selectAll();
	    }
	    
	    private void cutActionPerformed(ActionEvent evt) {
	    	editor.cut();
	    }
	    
	    private void pasteActionPerformed(ActionEvent evt) {
	    	pegadoInteligente();
	    }
	    
	    private void copyActionPerformed(ActionEvent evt) {
	    	editor.copy();
	   
	    }
	    
	    private void rehacerActionPerformed(ActionEvent evt) {
	    	undo.redo();
	    }
	    
	    private void deshacerActionPerformed(ActionEvent evt) {
	    	undo.undo();
	    }

	    
	    public void obtenerFoco() {
	    	editor.requestFocus();
	    }

	    private JMenuItem getBuscar() {
	    	if(buscar == null) {
	    		buscar = new JMenuItem();
	    		buscar.setText("Buscar");
	    		buscar.setBounds(104, 19, 49, 21);
	    	//	buscar.setBackground(new java.awt.Color(255,255,255));
	    		buscar.setAccelerator(KeyStroke.getKeyStroke("ctrl pressed F"));
	    		buscar.setFont(new java.awt.Font("Arial",0,12));
	    		buscar.addActionListener(new ActionListener() {
	    			public void actionPerformed(ActionEvent evt) {
	    				buscarActionPerformed(evt);
	    			}
	    		});
	    	}
	    	return buscar;
	    }
	    
	    private JSeparator getJSeparator4() {
	    	if(jSeparator4 == null) {
	    		jSeparator4 = new JSeparator();
	    		jSeparator4.setBounds(104, 19, 70, 8);
	    	}
	    	return jSeparator4;
	    }
	    
	    
	    public String getEditorText() {
	    	return editor.getText();
	    }
	    
	    
	    
	    public void requestEditorFocus(){
	    	editor.requestFocus();
	    }
	    
	    public int getEditorSelectionStart(){
	    	return editor.getSelectionStart();
	    }
	    
	    public int getEditorSelectionEnd(){
	    	return editor.getSelectionEnd();
	    	
	    }
	    
	    
	    public void editorReplaceSelection(String str) {
	    	editor.replaceSelection(str);
	    }
	    
	    public String getEditorSelectedText() {
	    	return editor.getSelectedText();
	    }
	    
	    
	    public int getEditorCaretPosition() {
	    	return editor.getCaretPosition();
	    }
	    
	    public Caret getEditorCaret() {
	    	return editor.getCaret();
	    }
	    
	    private void buscar() {
	    	
	    	if (buscarDialog == null) {
	    		buscarDialog= new Buscar(null);
	    		buscarDialog.setLocationRelativeTo(null);
	    		buscarDialog.conectar(this);
	    		buscarDialog.setVisible(true);
	    		buscarDialog.init();
	    	   	}
	    	else
	    	{	buscarDialog.setVisible(true);
	    		buscarDialog.init();
	    		}
	    	
	    	}
	    
	   
	    public String editorGetSelectedText() {
	    	return editor.getSelectedText();
	    }
	    
	    public void setEditorCaretPosition(int i) {
	    	editor.setCaretPosition(i);
	    }
	    
	    public void setEditorText(String str) {
	    	editor.setText(str);
	    }
	    
	    
	    public void moveEditorCaretPosition(int i){
	    
	    editor.moveCaretPosition(i);
	    
	    }
	    private void buscarActionPerformed(ActionEvent evt) {
	    buscar();
	    
	    }
	    
	    private JMenuItem getGuardaBorrador() {
	    	if(guardaBorrador == null) {
	    		guardaBorrador = new JMenuItem();
	    		guardaBorrador.setText("Guardar borrador");
	    		guardaBorrador.setBounds(-102, 65, 118, 22);
	    		//guardaBorrador.setBackground(new java.awt.Color(255,255,255));
	    		guardaBorrador.setFont(new java.awt.Font("Arial",0,12));
	    		guardaBorrador.setAccelerator(KeyStroke.getKeyStroke("ctrl pressed S"));
	    		guardaBorrador.addActionListener(new ActionListener() {
	    			public void actionPerformed(ActionEvent evt) {
	    				try {
							guardaBorradorActionPerformed(evt);
						} catch (TransformerException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
	    			}
	    		});
	    	}
	    	return guardaBorrador;
	    }
	    
	    
	    public String getVersion(){
			return version;
		}
	    
	    
	    private JSeparator getJSeparator5() {
	    	if(jSeparator5 == null) {
	    		jSeparator5 = new JSeparator();
	    		jSeparator5.setBounds(148, 65, 70, 8);
	    	}
	    	return jSeparator5;
	    }
	    
	    private void guardaBorradorActionPerformed(ActionEvent evt) throws TransformerException {
	    	try {
				guardar_borrador();
			} catch (IOException e) {
				JOptionPane.showMessageDialog( Main.this,"No se pudo establecer la conexión con el servidor.\n Chequea tu conexión a internet","Ups", JOptionPane.ERROR_MESSAGE );
				
			}
	    }
	    
	    private JComboBox getComboImagenes() {
	    	if(comboImagenes == null) {
	    		
	    		comboImagenes = new JComboBox();
	    		comboImagenes.setFont(arialPlain12);
	    		comboImagenes.addItem("");
	    		comboImagenes.setSelectedIndex(0);
	    		comboImagenes.addActionListener(new ActionListener() {
	    			public void actionPerformed(ActionEvent evt) {
	    				comboImagenesActionPerformed(evt);
	    			}
	    		});

	    	}
	    	
	    	return comboImagenes;
	    }
	    
	    	    
	  

	    private JLabel getJLabel6() {
	    	if(jLabel6 == null) {
	    		jLabel6 = new JLabel();
	    		jLabel6.setText("Estilos predefinidos");
	    		jLabel6.setFont(arialPlain12);
	    		jLabel6.setEnabled(false);
	    		jLabel6.setVisible(false);
	    	}
	    	return jLabel6;
	    }
	   
	    private JMenuItem getConfigEstilos() {
	    	if(configEstilos == null) {
	    		
	    		configEstilos = new JMenuItem();
	    		configEstilos.setText("Preferencias");
	    		configEstilos.setAccelerator(KeyStroke.getKeyStroke("ctrl pressed P"));
	    		configEstilos.setBounds(148, 73, 124, 23);
	    		//configEstilos.setBackground(new java.awt.Color(255,255,255));
	    		configEstilos.setFont(new java.awt.Font("Arial",0,12));
	    		configEstilos.addActionListener(new ActionListener() {
	    			public void actionPerformed(ActionEvent evt) {
	    				preferenciasActionPerformed(evt);
	    			}
	    		});
	    	}
	    	return configEstilos;
	    }
	    
	    private void preferenciasActionPerformed(ActionEvent evt) {
	    	
	    	mostrarPreferencias();
	    	
	    	
	    }

	    private JLabel getEstilosLabel() {
	    	if(estilosLabel == null) {
	    		estilosLabel = new JLabel();
	    		estilosLabel.setText("Estilos personalizados");
	    		estilosLabel.setFont(new java.awt.Font("Arial",0,12));
	    	}
	    	return estilosLabel;
	    }
	    
	   
	    
	    
	   private String traducirColor(String str) {
		   if (str.equals("Azul"))str="blue";
		   if (str.equals("Azul oscuro"))str="darkblue";
		   if (str.equals("Rojo oscuro"))str="darkred";
		   if (str.equals("Rojo"))str="red";
		   if (str.equals("Naranja"))str="orange";
		   if (str.equals("Marron"))str="brown";
		   if (str.equals("Amarillo"))str="yellow";
		   if (str.equals("Verde"))str="green";
		   if (str.equals("Oliva"))str="olive";
		   if (str.equals("Violeta"))str="violet";
		   if (str.equals("Negro"))str="black";
		   
		return str;
	   }

	   
	   
	    private void comboImagenesActionPerformed(ActionEvent evt) {
	    	if (!rellenandoImgs) {
	    	int index=comboImagenes.getSelectedIndex();
	  	    if (index!=0) {
	  	    	
	  	    editor.replaceSelection(Analizador.agregarImagen(listaImagenes.get(index-1)[1],false));
	      	editor.requestFocus();
	      	comboImagenes.setSelectedIndex(0);
	  	    }
	   }
	   
	    }
	    
	    private void aplicarEstilo() {
	    	
	    	if (!rellenandoEst) {
	    	
	    	int i = estilosComboBox.getSelectedIndex()-1;
	    	if (i>-1) {
	    	String seleccion = editor.getSelectedText();
	    	if (seleccion==null) seleccion="";
	    	String fuente,color,tam,negrita,sub,italica,inicio,fin,alineacion;
	    	inicio="";
	    	fin="";
	    	String[] arreglo=config.getEstilos().get(i);
	    	
	    	italica=arreglo[1];
	    	sub=arreglo[2];
	    	negrita=arreglo[3];
	    	fuente=arreglo[4];
	    	color=arreglo[5];
	    	tam=arreglo[6];
	    	alineacion=arreglo[7];
	    	if (italica.equals("S")) {
	    		inicio=inicio+"[i]";
	    		fin="[/i]"+fin;
	    	}
	    	if (sub.equals("S")) {
	    		inicio=inicio+"[u]";
	    		fin="[/u]"+fin;
	    	}
	    	if (negrita.equals("S")) {
	    		inicio=inicio+"[b]";
	    		fin="[/b]"+fin;
	    	}
	    	
	    	if (!(fuente.equals(""))) {
	    		inicio=inicio+"[font="+fuente+"]";
	    		fin="[/font]"+fin;
	    	}
	    	
	    	if (!(color.equals(""))) {
	    		
	    		inicio=inicio+"[color="+traducirColor(color)+"]";
	    		fin="[/color]"+fin;
	    	}
	    	
	    	if (!(tam.equals(""))) {
	    		inicio=inicio+"[size="+removePx(tam)+"]";
	    		fin="[/size]"+fin;
	    	}
	    	
	    	if (!(alineacion.equals(""))) {
	    		inicio=inicio+"[align="+convert(alineacion)+"]";
	    		fin="[/align]"+fin;
	    	}
	    	
	    	
	    editor.replaceSelection(inicio+seleccion+fin);
	    	
	    }
	    	estilosComboBox.setSelectedIndex(-1);
	    	
	    	}
	    }
	    
	   
	    
	    private String convert(String str) {
	    	if (str.equals("Izquierda")) str="left";
	    	if (str.equals("Derecha")) str="right";
	    	if (str.equals("Centro")) str="center";
	    	return str;
	    }
	    
	    
	    private String removePx(String str) {
	    	return str.replace("px","" );
	    	
	    }
	    
	    

	    
	    
	    private void estilosComboBoxActionPerformed(ActionEvent evt) {
	    	aplicarEstilo();
	    	editor.requestFocus();
	    }
	    
	    private JComboBox getEstilosComboBox() {
	    	if(estilosComboBox == null) {
	    		estilosComboBox = new JComboBox();
	    		estilosComboBox.setFont(arialPlain12);
	    		estilosComboBox.addActionListener(new ActionListener() {
	     			public void actionPerformed(ActionEvent evt) {
	     				estilosComboBoxActionPerformed(evt);
	     			}
	     		});

	    		   	}
	    	return estilosComboBox;
	    }

	   
	    
	    
	    
	    public void editorSetText(String str) {
	    	editor.setText(str);
	    	editor.getCaret();
	    }
	    
	  

	    public void editorRequestFocus() {
	    	editor.requestFocus();
	    }

	   
	   
	    
	    

	    private JMenu getAyuda() {
	    	if(ayuda == null) {
	    		ayuda = new JMenu();
	    		ayuda.setText("Ayuda");
	    		ayuda.setFont(arialPlain12);
	    	//	ayuda.setBackground(new java.awt.Color(255,255,255));
	    		//ayuda.setForeground(new java.awt.Color(0,0,0));
	    		ayuda.add(getJMenuItem5());
	    		ayuda.add(getBuscarAct());
	    		ayuda.add(getJMenuItem2());
	    	}
	    	return ayuda;
	    }
	   

	    
	    private void mostrarPreferencias(){
	      	/*if (cg==null) {
	    		cg = new ConfigGUI();
	    	
	    		}*/
	      	config.resetBoolean();
	      	config.resetSelection();
	      	config.cargar();
	      	config.setLocationRelativeTo(this);
	      	config.setVisible(true);
	    }

	    private void pegadoIntActionPerformed(ActionEvent evt) {
	    	
	    	
	    	
	    	if (pegadoInt.isSelected()) 
	    		{
	    		
	    		pegadoInteligente=false;
	    		sub_pegar.setText("Pegar");	
	    		
	    		}
	    	else
	    	{
	    		
	    		sub_pegar.setText("Pegado inteligente");
	    		pegadoInteligente=true;
	    }
	    }
	    
	    
	 
	    
	   
	    
	    private JButton getJButton2() {
	    	if(btnDailyMotion == null) {
	    		btnDailyMotion = new JButton();
	    		btnDailyMotion.setIcon(new ImageIcon(getClass().getResource("dailymotion.png")));
	    		btnDailyMotion.setBorderPainted(false);
	    		btnDailyMotion.setPreferredSize(new java.awt.Dimension(30,30));
	    		btnDailyMotion.setToolTipText("Insertar video de DailyMotion");
	    		btnDailyMotion.setSize(30, 30);
	    		btnDailyMotion.addActionListener(new ActionListener() {
	    			public void actionPerformed(ActionEvent evt) {
	    				btnDailyMotionActionPerformed(evt);
	    			}
	    		});
	    	}
	    	return btnDailyMotion;
	    }
	    
	    private void btnDailyMotionActionPerformed(ActionEvent evt) {
	    	    		String seleccion=editor.getSelectedText();
		if (!(dialogo.isVisible() | (dialogo2.isVisible()))) {
			if (seleccion != null) 
				
			editor.replaceSelection(Analizador.agregarDailyMotion(seleccion,true));
		
			else
		{
			dialogo.setTipo("dailymotion");
			dialogo.setLinkEnabled(true);
			dialogo.setTitle("Insertar video desde DailyMotion");
			dialogo.cambiarLabel("Ingresa la URL completa");
			dialogo.setVisible(true);
						
		}
	}
		dialogo.obtenerFoco();
	}
	    
	    
	    private JButton getJButton3() {
	    	if(btnMetaCafe == null) {
	    		btnMetaCafe = new JButton();
	    		btnMetaCafe.setIcon(new ImageIcon(getClass().getResource("metacafe.png")));
	    		btnMetaCafe.setBorderPainted(false);
	    		btnMetaCafe.setPreferredSize(new java.awt.Dimension(30,30));
	    		btnMetaCafe.setToolTipText("Insertar Video de Metacafe");
	    		btnMetaCafe.setSize(30, 30);
	    		btnMetaCafe.addMouseListener(new MouseAdapter() {
	    			public void mouseClicked(MouseEvent evt) {
	    				btnMetaCafeMouseClicked(evt);
	    			}
	    		});
	    	}
	    	return btnMetaCafe;
	    }
	    
	    private void btnMetaCafeMouseClicked(MouseEvent evt) {
	    		String seleccion=editor.getSelectedText();
		if (!(dialogo.isVisible() | (dialogo2.isVisible()))) {
			if (seleccion != null) 
				
			editor.replaceSelection(Analizador.agregarMetacafe(seleccion,true));
		
			else
		{
			dialogo.setTipo("metacafe");
			dialogo.setLinkEnabled(true);
			dialogo.setTitle("Insertar video desde Metacafe");
			dialogo.cambiarLabel("Ingresa la URL completa");
			dialogo.setVisible(true);
						
		}
	}
		dialogo.obtenerFoco();
	}

	    
	    private void CrearFuentesPopUp() {
			for (int i=0;i<10;i++){
				if (fuentesPersonales[i]==null) fuentesPersonales[i]=new JMenuItem();
				fuentesPersonales[i].setFont(new java.awt.Font("Ubuntu",0,12));
				sub_fuente.add(fuentesPersonales[i]);
				fuentesPersonales[i].setVisible(false);
				fuentesPersonales[i].addActionListener(new ActionListener()
				{
					public void actionPerformed(ActionEvent evt) {
					     
						insertarFuentePopup((evt.getActionCommand()));
					    
					}
				});
				
							
			}
		}
	    
	    
	    String[] concat(String[] A, String[] B) {
	    	String[] C= new String[A.length+B.length];
	    	   System.arraycopy(A, 0, C, 0, A.length);
	    	   System.arraycopy(B, 0, C, A.length, B.length);

	    	   return C;
	    	}
		
		public void insertarFuentes(){
			int cantidad;
			
			fuentesP=config.getFuentesP();
			String[] temp;
			cantidad=fuentesP.size();
			String[] fuentesPArray = new String[cantidad];
			
			for (int i=0;i<10;i++){
				fuentesPersonales[i].setVisible(false);
					
			}
			fuentesP.toArray(fuentesPArray);
			temp=concat(stringFuentes,fuentesPArray);
			fonts.setModel(new DefaultComboBoxModel(temp));
			if (!fuentesP.isEmpty()) {
				int pos = fuentesP.size();
				
				
				System.out.println(pos);
				for (int i=0;i<pos;i++)
				{
					fuentesPersonales[i].setText(fuentesP.get(i));
					fuentesPersonales[i].setVisible(true);
					
							
				}
				
				
			}
			
		}
	    
	    
		
		public void editorReplaceAll(String a,String b) {
			editor.setText(editor.getText().replaceAll(a,b));
		}
	    
		
		private boolean esImagen(String str) {
			
			if (str!=null && (str.startsWith("[img=") | str.startsWith("[img]"))) return true;
			else return false;
		}
		
		private String getImagen(String str) {
			int a,b;
			int tipo;
			if (str.startsWith("[img=")) tipo=1;
				else tipo=2;
			
			System.out.println("Tipo: "+tipo);
			if (tipo==1){
			
				a=str.indexOf('=');
			b=str.indexOf(']',a+1);
			}			
			else //tipo 2
			{
				a=str.indexOf(']');
				b=str.indexOf("[/",a+1);
			}
			return str.substring(a+1,b).trim();
			
		}
		
		private void editorKeyReleased(KeyEvent evt) {
			
			caracteres=editor.getDocument().getLength();
			int tope1=tope/3;
			int tope2=tope1*2;
			if (caracteres<tope1) progressBar.setForeground(colorVerde);
			if (caracteres<tope2&&caracteres>tope1) progressBar.setForeground(colorAmarillo);
			if (caracteres<tope&&caracteres>tope2) progressBar.setForeground(colorNaranja);
			if (caracteres==tope+1){
				progressBar.setForeground(colorRojo);
				lblChars.setForeground(colorRojo);
			}else lblChars.setForeground(colorNegro);
			progressBar.setValue(caracteres*100/tope);
			lblChars.setText(Integer.toString(caracteres));
			
			
			
		}

		private void checkUpdates(boolean silent) {
			
			String nextLine;
			String versionObtenida,web;
		    URL url = null;
		    JTextArea texto;
		    URLConnection urlConn = null;
		    InputStreamReader  inStream = null;
		    BufferedReader buff = null;
		    try{
		       // Create the URL obect that points
		       // at the default file index.html
		       url  = new URL("http://dl.dropbox.com/u/155504/version.txt" );
		       urlConn = url.openConnection();
		      inStream = new InputStreamReader(urlConn.getInputStream());
		        buff= new BufferedReader(inStream);
		   	     
	    	
		         nextLine =buff.readLine(); //Encabezado  
		         versionObtenida =buff.readLine(); //version
		         nextLine =buff.readLine(); //Encabezado
		         web =buff.readLine(); //Link
		         if (Float.parseFloat(versionObtenida)>Float.parseFloat(version))
		         {
		        	  texto= new JTextArea("Hay una nueva version de PosT!NGA disponible ("+versionObtenida+"). Entra a "+web+" para mas detalles");
		        	 JOptionPane.showMessageDialog(null,texto, "Actualizacion disponible", JOptionPane.INFORMATION_MESSAGE);
		         }
		             else if (silent) System.out.println("PosT!NGA esta actualizado");
		             		else JOptionPane.showMessageDialog(null,"PosT!NGA se encuentra actualizado", "Buscar actualizaciones", JOptionPane.INFORMATION_MESSAGE);
		             
		         }
		         
		
		  catch(IOException  e1){
		   System.out.println("Error al conectar con el servidor"); 
		   JOptionPane.showMessageDialog( Main.this,"No se pudo establecer la conexión con el servidor.\n Chequea tu conexión a internet","Ups", JOptionPane.ERROR_MESSAGE );
		}
		}
		
		
		
		private void buscarActActionPerformed(ActionEvent evt) {
			checkUpdates(false);
		}
		
		private void tituloFocusGained(FocusEvent evt) {
			if (titulo.getText().equals(tituloDefault)) {
				titulo.setText("");
				titulo.setFont(new java.awt.Font("DejaVu Sans",0,12));
			}
		}
		
		
		
		
		private void initTitulo() {
			titulo.setFont(new java.awt.Font("DejaVu Sans",2,10));
			titulo.setText(tituloDefault);
			titulo.setHorizontalAlignment(JTextField.CENTER);
		}
		
		
		private void jTagsFocusGained(FocusEvent evt) {
			if (jTags.getText().equals(tagsDefault)) {
				jTags.setText("");
				jTags.setFont(new java.awt.Font("DejaVu Sans",0,12));
				
			}
		}
		
		public void tituloTagsFuentesNormales() {
			titulo.setFont(new java.awt.Font("DejaVu Sans",0,12));
			jTags.setFont(new java.awt.Font("DejaVu Sans",0,12));
		}
		
		
		private void initTags() {
			jTags.setFont(new java.awt.Font("DejaVu Sans",2,10));
			jTags.setText(tagsDefault);
			jTags.setHorizontalAlignment(JTextField.CENTER);
		}
		
		private void tituloFocusLost(FocusEvent evt) {
			if (titulo.getText().equals("")) {
				initTitulo();
			}
		}
		
		
		private void jTagsFocusLost(FocusEvent evt) {
			if (jTags.getText().equals("")) {
				initTags();
			}
		}

		
		private JComboBox getJComboBox1() {
			if(comboCat == null) {
				ComboBoxModel categoriasModel = 
					new DefaultComboBoxModel(categorias);
				comboCat = new JComboBox();
				comboCat.setModel(categoriasModel);
				comboCat.setFont(new java.awt.Font("Arial",0,12));
				comboCat.setPreferredSize(new java.awt.Dimension(175, 23));
				comboCat.setForeground(new java.awt.Color(0,0,0));
			}
			return comboCat;
		}
		
		private JComboBox getJComboBox2() {
			if(comboComu == null) {
				 
					
				comboComu = new JComboBox();
				
				comboComu.setFont(new java.awt.Font("Arial",0,11));
				comboComu.setPreferredSize(new java.awt.Dimension(175, 23));
				comboComu.setForeground(new java.awt.Color(0,0,0));
			}
			return comboComu;
		}
		
		private JComboBox getJComboBox3() {
			if(comboCatP == null) {
				ComboBoxModel categoriasPModel = 
					new DefaultComboBoxModel(categoriasP);
				comboCatP = new JComboBox();
				comboCatP.setModel(categoriasPModel);
				comboCatP.setFont(new java.awt.Font("Arial",0,11));
				comboCatP.setPreferredSize(new java.awt.Dimension(175, 23));
				comboCatP.setForeground(new java.awt.Color(0,0,0));
			}
			return comboCatP;
		}
		
		private JLabel getCat() {
			if(cat == null) {
				cat = new JLabel();
				cat.setText("Categoria");
				cat.setFont(new java.awt.Font("Arial",0,12));
			}
			return cat;
		}
		
		private JButton getbPostear() {
			if(bPostear == null) {
				bPostear = new JButton();
				bPostear.setText("Postear!");
				bPostear.setIcon(new ImageIcon(Main.class.getResource("post.png")));
				bPostear.setFont(fuenteBoton);
				bPostear.setSize(112, 41);
				bPostear.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						try {
							
							bPostearActionPerformed(evt);
						} catch (Exception e) {
							
						}
					}
				});
			}
			return bPostear;
		}
		
		
		
		private boolean tagsBienFormados() {
			
			if (jTags.getText().startsWith(",")) return false;
			if (jTags.getText().endsWith(",")) return false;
			
			return true;
		}
		
		private boolean checkFuentes() {
			
			
			if ( fuentes.checkFuentes() || checkRecopilacion.isSelected()) {
				
				return true;
			}
			else { 
				
				JOptionPane.showMessageDialog( Main.this,"La fuente es requerida","Ups!", JOptionPane.INFORMATION_MESSAGE );
				
				return false;
			}

		}
		
		
		private boolean checkFuentesCorrectas() throws Exception {
			if ( agregarFuentes()) return true;
			else {
				JOptionPane.showMessageDialog( Main.this,"El formato de al menos una fuente de informacion es incorrecto","Ups!", JOptionPane.INFORMATION_MESSAGE );
				return false;
			}
				
			//return false;
		}
		
		private boolean checkCategoria() {
			
			if (comboCat.getSelectedIndex()<1) {
				JOptionPane.showMessageDialog( Main.this,"Selecciona una categoria","Ups!", JOptionPane.INFORMATION_MESSAGE );
				return false;
			}else
				return true;
			
		}
			private boolean checkCategoriaP() {
			
			if (comboCatP.getSelectedIndex()<1) {
				JOptionPane.showMessageDialog( Main.this,"Selecciona una categoria","Ups!", JOptionPane.INFORMATION_MESSAGE );
				return false;
			}else
				return true;
			
		}
		
		private boolean checkComunidad() {
			
			if (comboComu.getSelectedIndex()<1) {
				JOptionPane.showMessageDialog( Main.this,"Selecciona la comunidad","Ups!", JOptionPane.INFORMATION_MESSAGE );
				return false;
			}else
				return true;
			
		}
		
		
		
		private boolean checkTags() {
			
			String[] results = jTags.getText().split(",");
			int tam = results.length;
			
			if (tam>=4 && tagsBienFormados()) 
				{
				return true;
				} else
				{
					
					JOptionPane.showMessageDialog( Main.this,"Los tags son incorrectos. Asegurate que sean como mínimo 4 y separados por coma","Ups!", JOptionPane.INFORMATION_MESSAGE );
					return false;
				}
			
			
		}
		
		
		
		private boolean checkRepost() throws Exception {
		boolean continuar=false;
		
				if (esRepost(titulo.getText())) {
				
					while (!continuar) {
				int seleccion = JOptionPane.showOptionDialog(this, // Componente padre
					    "Ya exite en T! un post con el mismo título.\nPuede que estés haciendo un repost\n¿Estás seguro de continuar?\n(Corres el riesgo de que te lo eliminen)",
					    "Epaa, posible repost a la vista",
					    JOptionPane.YES_NO_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE,null,new Object[] { "Si", "Ver resultado","No"},   
					    "No");
				 System.out.println(seleccion);
				 if((seleccion + 1)==0) return false;  
				 if((seleccion + 1)==2)
				   {
					   irAbuscador(titulo.getText());
					   System.out.println("VER");
				   }
				   
				    if((seleccion + 1)==1) {
				    	System.out.println("SI");
						 return true;
						   
					   }
				   
				    if((seleccion + 1)==3) {
						   
						   System.out.println("NO");
						   
						      continuar=true;
				     
				    }
				   

				}
				return !continuar;
				}
				else //no hay repost
					return true;
						
		}
		
		
		private boolean checkRepostP() throws Exception {
			boolean continuar=false;
			
					if (esRepost(titulo.getText())) {
					
						while (!continuar) {
					int seleccion = JOptionPane.showOptionDialog(this, // Componente padre
						    "Ya exite en P! un post con el mismo título.\nPuede que estés haciendo un repost\n¿Estás seguro de continuar?\n(Corres el riesgo de que te lo eliminen)",
						    "Epaa, posible repost a la vista",
						    JOptionPane.YES_NO_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE,null,new Object[] { "Si", "Ver resultado","No"},   
						    "No");
					 System.out.println(seleccion);
					 if((seleccion + 1)==0) return false;  
					 if((seleccion + 1)==2)
					   {
						   irAbuscador(titulo.getText());
						   System.out.println("VER");
					   }
					   
					    if((seleccion + 1)==1) {
					    	System.out.println("SI");
							 return true;
							   
						   }
					   
					    if((seleccion + 1)==3) {
							   
							   System.out.println("NO");
							   
							      continuar=true;
					     
					    }
					   

					}
					return !continuar;
					}
					else //no hay repost
						return true;
							
			}
			
		

		
		private boolean checkEsCrap() {
			if (editor.getText().length()<60) {		
			
				int seleccion = JOptionPane.showOptionDialog(this, // Componente padre
					    "Mmm, tu post huele a CRAP.\n¿Estás seguro de continuar?\n(Corres el riesgo de que te lo eliminen)",
					    "No seas crapero/a",
					    JOptionPane.YES_NO_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE,null,new Object[] { "Si", "No"},   
					    "Si");
				
				   if((seleccion + 1)==1)
				   {
				      return false;
				   }
				   else
				   {
				      return true;
				   }
				
			}else
				return false;
			
		}
		
		private String truncarTitulo(String str) {
			if (str.trim().length()>60) {
				return str.substring(0,60);
			}else
				return str.trim();
		}
		private boolean checkPuedoPostear() {
			if (!puedoPostear)	JOptionPane.showMessageDialog( Main.this,"No podés postear tan seguido, espera unos instantes","Ups!", JOptionPane.INFORMATION_MESSAGE );
				return puedoPostear;
			}
		
		
		private boolean checkLongitud() {
			if (caracteres>63206) {
				JOptionPane.showMessageDialog( Main.this,"El post no puede exceder los 63206 caracteres","Ups!", JOptionPane.INFORMATION_MESSAGE );
				return false;
			}else
				return true;
		}
		private boolean checkTitulo() {
			boolean resultado = true;
			if (titulo.getText().trim().equals(tituloDefault)) {
				
				JOptionPane.showMessageDialog( Main.this,"Colocale un título al post","Ups!", JOptionPane.INFORMATION_MESSAGE );
				return false;
			}
			
					
		
			if (isUpperCase(titulo.getText().trim()))
			{
				JOptionPane.showMessageDialog( Main.this,"El título no debe estar en mayusculas","Ups!", JOptionPane.INFORMATION_MESSAGE );
				return false;
			}
			return resultado;
		}
		private boolean isUpperCase(String s)
		{
		        for (int i=0; i<s.length(); i++)
		        {
		                if (!Character.isUpperCase(s.charAt(i)))
		                {
		                        return false;
		                }
		        }
		        return true;
		}
		
		public String getUserKey() {
			return key;
		}
		
		public void getUserKey(String usuario,String pass) throws Exception {
		      String nextLine;
		       URL url = null;
		       CharSequence llave="";
		       URLConnection urlConn = null;
		       InputStreamReader  inStream = null;
		       BufferedReader buff = null;
		       if (login(usuario,pass)) {
		       try{
		          // Create the URL obect that points
		          // at the default file index.html
		         
		        	  url  = new URL("http://www.taringa.net");
		        	
		        	
		          
		          urlConn = url.openConnection();
		          cook.writeCookies(urlConn, false);
		         inStream = new InputStreamReader( 
		                           urlConn.getInputStream());
		           buff= new BufferedReader(inStream);
		        
		       // Read and print the lines from index.html
		        while (true){
		            nextLine =buff.readLine();  
		            
		            if (nextLine !=null){
		           
		                if (nextLine.contains("user_key:"))
		                {	
		                		                
		                int lin=nextLine.indexOf("user_key: '")+11;
		                key=(String)(nextLine.substring(lin,nextLine.indexOf("'",lin)));
		                
		                }
		            }
		            else{
		               break;
		            } 
		        }
		     } catch(MalformedURLException e){
		       System.out.println("Please check the URL:" + 
		                                           e.toString() );
		     } catch(IOException  e1){
		      System.out.println("Can't read  from the Internet: "+ 
		                                          e1.toString() ); 
		  }
		     
		             
		         }
		}
		         
		
		public boolean login(String nick, String pass) throws Exception {
			boolean exito = false;
			if (nick.equals("") | pass.equals("")) {
				JOptionPane.showMessageDialog( Main.this,"Usuario o contraseña no seteados.\nEn las preferencias lo podés hacer","Ups", JOptionPane.ERROR_MESSAGE );
				return exito;
			}
			else {
							
				
				URL siteUrl = new URL("https://www.taringa.net/registro/login-submit.php");
			

			HttpURLConnection conn = (HttpURLConnection) siteUrl.openConnection();
			conn.setRequestMethod("POST");
			conn.setDoOutput(true);
			conn.setDoInput(true);
			DataOutputStream out = new DataOutputStream(conn.getOutputStream());
			System.out.println("Logueandose "+"como el usuario: "+nick);
			out.writeBytes("connect=&redirect=%2F&nick="+nick+"&pass="+pass+"&=");
			out.flush();
			out.close();
			cook.readCookies(conn, false, false);
			BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
			String line = "";
			line=in.readLine();
			
			if (line.contains(":1")) exito=true;
			
			in.close();
			if (!exito) JOptionPane.showMessageDialog( Main.this,"Usuario o contraseña inválidos","Ups", JOptionPane.ERROR_MESSAGE );
			return exito;
			}
		}	
		
		public void habiliarPost() {
			bPostear.setEnabled(true);
		}
		
		
		public String encode(String in) {
			String encodedurl="";
			  try{
				  encodedurl= URLEncoder.encode(in,"UTF-8"); 
			   
			  }catch(UnsupportedEncodingException uee){
			   System.err.println(uee);
			  }
			  finally {
				  return encodedurl;
			  }
		}
		
		private int getCategoria() {
			return categoriasNum[comboCat.getSelectedIndex()];
		}
		private int getCategoriaP() {
			return categoriasNumP[comboCatP.getSelectedIndex()];
		}
		
		private String getComunidadURL() {
			int a=comboComu.getSelectedIndex();
			return "www.taringa.net"+listaComunidades.get(a-1)[0];
		}
		
		
		private  boolean esRepost(String contenido) throws Exception {
		    
		     
		       HttpURLConnection conn;
		       URL siteUrl = null;
			   if (modo==0) siteUrl = new URL("http://buscar.taringa.net/posts?engine=taringa&q="+encode(contenido)+"&en=todo");
			   if (modo==2) siteUrl = new URL("http://www.poringa.net/buscar/?q="+encode(contenido));
			   conn = (HttpURLConnection) siteUrl.openConnection();
			conn.setRequestMethod("GET");
			conn.setDoOutput(true);
			conn.setDoInput(true);
			DataOutputStream out = new DataOutputStream(conn.getOutputStream());

			out.flush();
			out.close();
			BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
			String todo="";
			String line = "";
			while((line=in.readLine())!=null) {
				todo=todo+line+"\n";
			}
			
			in.close();
			
			 if (todo.toLowerCase().contains("<a title=\""+contenido.toLowerCase()+"\" href="))	return true;
			
			else return false;
			/*
			else if (todo.contains("<a title=\""+contenido+"\" href=")) System.out.println("Posibilidad de repost: alta");
			else System.out.println("Con los elementos que tengo no puedo determinar si hay posibilidad de repost");
			*/
			
		}
		
		private void nuevoPost() {
			titulo.setText(tituloDefault);
			editor.setText("");
			jTags.setText(tagsDefault);
			comboCat.setSelectedIndex(0);
			comboCatP.setSelectedIndex(0);
			comboComu.setSelectedIndex(0);
			radioTodos.setSelected(true);
			rangos.setSelectedIndex(2);
			borradorID="";
			fuentes.reset();
		
			}
		
		
		private String getBorradorId(String str) {
			String [] arr =	str.split("\"data\":");
			arr[1]=arr[1].substring(0,arr[1].length()-1);
			return arr[1].trim();
		}
		
		public  void postearEnT(String usuario, String pass,boolean conCaptcha,String captcha1,String captcha2) throws Exception {
			String contenido="";
			
			DataOutputStream out;
			String postID = null;
			String categoria="";
			String contenidoPropio="";
			boolean mandoCap;
			categoria=Integer.toString(getCategoria());
			if (checkRecopilacion.isSelected()) contenidoPropio="&sources_flag=on";
			else
				contenidoPropio="";
			
			String agregar="http://www.taringa.net/agregar2.php";
				
		    String line;
		    HttpURLConnection conn,conn1;
		    URL siteUrl, siteUrl1;
		    String respuesta;
		    BufferedReader in;
		    
		    if (!conCaptcha) {
		    login(usuario,pass);
		    System.out.println("Haciendo POST a: "+agregar);
			siteUrl = new URL(agregar);
			conn = (HttpURLConnection) siteUrl.openConnection();
			conn.setRequestMethod("POST");
			cook.writeCookies(conn, false);
			conn.setDoOutput(true);
			conn.setDoInput(true);
			out = new DataOutputStream(conn.getOutputStream());
			//key=&id=&borrador_id=&titulo=Linux&cuerpo=juaaa&sources_flag=on&categoria=15&tags=t1%2Ct2%2Ct3%2Ct4&continue=Previsualizar
			
			
			contenido="key="+key+"&id=&borrador_id=&titulo="+encode(truncarTitulo(titulo.getText()))+"&cuerpo="+encode(editor.getText()+propaganda)+fuentesDeInfo+contenidoPropio+"&categoria="+categoria+"&tags="+encode(jTags.getText())+getComentariosStatus()+"&continue=Previsualizar";
			//contenido="key="+key+"&id=&borrador_id=&titulo="+encode(truncarTitulo(titulo.getText()))+"&cuerpo="+encode(editor.getText()+propaganda)+"&sources_flag=on&categoria="+categoria+"&tags="+encode(jTags.getText())+"&continue=Previsualizar";
			
			

			out.writeBytes(contenido);
			out.flush();
		//	out.close();
			in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
			line = "";
			respuesta="";
			
			//"status":0,"data":"No puedes realizar tantas acciones en tan poco tiempo. Vuelve a intentarlo en unos instantes"
			//"status":1,"data" El post fue publicado satisfactoriamente
			//"status":2,"data":"6Le8jQQAAAAAAGt1bzJsaHKCoLMWt6NFHupdtxf9"
			//status":3 "El código de la imagen es incorrecto"}
			
			
			while((line=in.readLine())!=null){
				respuesta=respuesta+line;
				
			}
			
			//postID=procesar(temp);
			System.err.println("T! me devuelve: "+HtmlEntities.decode(respuesta));
			
					
			mandoCap=false;
			
			//T! me devuelve: {"status":1,"data":{"text":"El post <strong>sss<\/strong> fue publicado satisfactoriamente<br \/>Serás redireccionado al post en <span class='num'>9<\/span> segundos","url":"\/posts\/animaciones\/13844332\/sss.html"}}
			
			if (respuesta.contains("\"status\":1")){
				JOptionPane.showMessageDialog( Main.this,"El post "+titulo.getText()+" fue publicado satisfactoriamente","Info", JOptionPane.INFORMATION_MESSAGE );
				//postID=procesar(respuesta);
				//eliminarPost(postID);
				insertarPausa();
				
				cook.clearCookies();
				comboCat.setSelectedIndex(0);
				out.close();
			}
			System.err.println("T! me devuelve: "+HtmlEntities.decode(respuesta));
			if (respuesta.contains("\"status\":2,")){
				
				mandoCap=true;
			}
			
			if (!respuesta.contains("fue publicado satisfactoriamente") && (!respuesta.contains("status\":2,\"data\""))) JOptionPane.showMessageDialog( Main.this,HtmlEntities.decode(respuesta.substring(20,respuesta.length()-2)),"Info", JOptionPane.INFORMATION_MESSAGE );
			//if (respuesta.contains("\"status\":3")) JOptionPane.showMessageDialog( Main.this,"El captcha ingresado es incorrecto","Info", JOptionPane.INFORMATION_MESSAGE ); 
			in.close();
			
			
			if (mandoCap) { //mando captcha
			
					siteUrl1 = new URL("http://www.google.com/recaptcha/api/challenge?k=6Le8jQQAAAAAAGt1bzJsaHKCoLMWt6NFHupdtxf9&ajax=1&cachestop=0.7112845726787665&lang=es");
				
   
				conn1 = (HttpURLConnection) siteUrl1.openConnection();
				   out.flush();
				 
				   BufferedReader in2 = new BufferedReader(new InputStreamReader(conn1.getInputStream()));
					String line2 = "";
					
					while((line2=in2.readLine())!=null)	 
						if(line2.contains("challenge :")){ challenge=line2;break;}
					String [] arr =	challenge.split("challenge : '");
					challenge=arr[1];
					
					challenge=challenge.substring(0,challenge.indexOf("'"));
					System.out.println("Challenge: "+challenge);
					
					
					if (cap==null) cap=new Captcha(this);
					/*
					 * muestro la ventana para ingresar el captcha
					 */
					cap.setModo(0);
					bPostear.setEnabled(false);
					cap.setLocationRelativeTo(this);
					cap.setVisible(true);
					cap.resetGui();
					
					cap.mostrarImagen("http://www.google.com/recaptcha/api/image?c="+challenge);
					
			}
					
			}
			else //viene con captcha
				/*
				 * ya mostre la ventana para ingresar captcha y tengo que mandar el POST
				 */
			{
				
				System.out.println("Ya ingrese el captcha");
				System.out.println("Challenge: "+challenge);
				System.out.println(captcha1+"+"+captcha2);
				siteUrl = new URL(agregar);
				conn = (HttpURLConnection) siteUrl.openConnection();
				conn.setRequestMethod("POST");
				cook.writeCookies(conn, false);
				conn.setDoOutput(true);
				conn.setDoInput(true);
				
				out = new DataOutputStream(conn.getOutputStream());
				contenido="key="+key+"&id=&borrador_id=&titulo="+encode(truncarTitulo(titulo.getText()))+"&cuerpo="+encode(editor.getText()+propaganda)+fuentesDeInfo+contenidoPropio+"&categoria="+categoria+"&tags="+encode(jTags.getText())+getComentariosStatus()+"&continue=Previsualizar"+"&recaptcha_challenge_field="+challenge+"&recaptcha_response_field="+captcha1+"+"+captcha2;
				//contenido="key="+key+"&id=&borrador_id=&titulo="+encode(truncarTitulo(titulo.getText()))+"&cuerpo="+encode(editor.getText()+propaganda)+"&sources_flag=on&categoria="+categoria+"&tags="+encode(jTags.getText())+"&continue=Previsualizar"+"&recaptcha_challenge_field="+challenge+"&recaptcha_response_field="+captcha1+"+"+captcha2;
				
				
				out.writeBytes(contenido);
				out.flush();
//				out.close();
				in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
				line = "";
				respuesta="";
				
				while((line=in.readLine())!=null)respuesta=respuesta+line; 
			//	postID=procesar(respuesta);
				System.err.println("T! me devuelve: "+HtmlEntities.decode(respuesta));
							
								
				if (respuesta.contains("\"status\":1")){
					JOptionPane.showMessageDialog( Main.this,"El post "+titulo.getText()+" fue publicado satisfactoriamente","Info", JOptionPane.INFORMATION_MESSAGE );
				
			//		postID=procesar(respuesta);
				//	eliminarPost(postID);
					insertarPausa();
					
					comboCat.setSelectedIndex(0);
					cook.clearCookies();
					out.close();
				}
				if (respuesta.contains("\"status\":3")) JOptionPane.showMessageDialog( Main.this,HtmlEntities.decode(respuesta.substring(20,respuesta.length()-2)),"Info", JOptionPane.INFORMATION_MESSAGE );
						
				//if (respuesta.contains("\"status\":3")) JOptionPane.showMessageDialog( Main.this,"El captcha ingresado es incorrecto","Info", JOptionPane.INFORMATION_MESSAGE ); 
				in.close();
			}
		    
			}
		
		private void insertarPausa() {
			if (timer2==null) timer2=new Timer();
			timer2.schedule(timerTask2, 60000);
			puedoPostear=false;
		}
			
		public  void postearEnP(String usuario, String pass,boolean conCaptcha,String captcha1,String captcha2) throws Exception {
			
			
			String contenido="";
			DataOutputStream out;
			String categoriaP="";
			String contenidoPropio="";
			categoriaP=Integer.toString(getCategoriaP());
			
			if (checkRecopilacion.isSelected()) contenidoPropio="&sources_flag=on";
			else
				contenidoPropio="";
			
			String agregar="http://www.poringa.net/agregar2.php";
				
		    String line;
		    HttpURLConnection conn,conn1;
		    URL siteUrl, siteUrl1;
		    String respuesta;
		    BufferedReader in;
		    
		    if (!conCaptcha) {
		    login(usuario,pass);
		    System.out.println("Haciendo POST a: "+agregar);
			siteUrl = new URL(agregar);
			conn = (HttpURLConnection) siteUrl.openConnection();
			conn.setRequestMethod("POST");
			cook.writeCookies(conn, false);
			conn.setDoOutput(true);
			conn.setDoInput(true);
			out = new DataOutputStream(conn.getOutputStream());
	
			


			contenido="key="+key+"&id=&borrador_id=&titulo="+encode(truncarTitulo(titulo.getText()))+"&cuerpo="+encode(editor.getText()+propaganda)+fuentesDeInfo+contenidoPropio+"&categoria="+categoriaP+"&tags="+encode(jTags.getText())+getComentariosStatus()+"&continue=Previsualizar";

			
			System.out.println(contenido);

			out.writeBytes(contenido);
			out.flush();
			in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
			line = "";
			respuesta="";
			
			
			
			while((line=in.readLine())!=null)respuesta=respuesta+line; 
			System.out.println("P! me devuelve: "+HtmlEntities.decode(respuesta));
			
			
			if (!respuesta.contains("fue publicado satisfactoriamente") && (!respuesta.contains("status\":2,\"data\""))) JOptionPane.showMessageDialog( Main.this,HtmlEntities.decode(respuesta.substring(20,respuesta.length()-2)),"Info", JOptionPane.INFORMATION_MESSAGE );
			
			boolean mandoCap=false;
			if (respuesta.contains("fue publicado satisfactoriamente")){
				if (timer2==null) timer2=new Timer();
				timer2.schedule(timerTask2, 60000);
				puedoPostear=false;
				JOptionPane.showMessageDialog( Main.this,"El post "+truncarTitulo(titulo.getText())+" fue publicado satisfactoriamente","Info", JOptionPane.INFORMATION_MESSAGE );
				cook.clearCookies();
				comboCatP.setSelectedIndex(0);
				out.close();
			}
			if (respuesta.contains(":2"))
				{
				mandoCap=true;
				System.out.println("Mando captcha");
				}
			
					
			//if (respuesta.contains("\"status\":3")) JOptionPane.showMessageDialog( Main.this,"El captcha ingresado es incorrecto","Info", JOptionPane.INFORMATION_MESSAGE ); 
			in.close();
			
			
			if (mandoCap) { //mando captcha
			
					siteUrl1 = new URL("http://www.google.com/recaptcha/api/challenge?k=6Le9jQQAAAAAADUXWDQ3Bj9mqDYQSWHHTghMuUVf&ajax=1&cachestop=0.9613815832396283&lang=es");
					                                         //recaptcha/api/challenge?k=6Le9jQQAAAAAADUXWDQ3Bj9mqDYQSWHHTghMuUVf&ajax=1&cachestop=0.9613815832396283&lang=es


   
				conn1 = (HttpURLConnection) siteUrl1.openConnection();
				   out.flush();
				 
				   BufferedReader in2 = new BufferedReader(new InputStreamReader(conn1.getInputStream()));
					String line2 = "";
					
					while((line2=in2.readLine())!=null)	 
						if(line2.contains("challenge :")){ challenge=line2;break;}
					String [] arr =	challenge.split("challenge : '");
					challenge=arr[1];
					
					challenge=challenge.substring(0,challenge.indexOf("'"));
					System.out.println("Challenge (P!): "+challenge);
					
					
					if (cap==null) cap=new Captcha(this);
					/*
					 * muestro la ventana para ingresar el captcha
					 */
					cap.setModo(2);
					bPostear.setEnabled(false);
					cap.setLocationRelativeTo(this);
					cap.setVisible(true);
					cap.resetGui();
					
					cap.mostrarImagen("http://www.google.com/recaptcha/api/image?c="+challenge);
					
			}
					
			}
			else //viene con captcha
				/*
				 * ya mostre la ventana para ingresar captcha y tengo que mandar el POST
				 */
			{
				
				System.out.println("Ya ingrese el captcha (P!)");
				System.out.println("Challenge (P!): "+challenge);
				System.out.println(captcha1+"+"+captcha2);
				siteUrl = new URL(agregar);
				conn = (HttpURLConnection) siteUrl.openConnection();
				conn.setRequestMethod("POST");
				cook.writeCookies(conn, false);
				conn.setDoOutput(true);
				conn.setDoInput(true);
				
				out = new DataOutputStream(conn.getOutputStream());
				contenido="key="+key+"&id=&borrador_id=&titulo="+encode(truncarTitulo(titulo.getText()))+"&cuerpo="+encode(editor.getText()+propaganda)+fuentesDeInfo+contenidoPropio+"&categoria="+categoriaP+"&tags="+encode(jTags.getText())+"&continue=Previsualizar&recaptcha_challenge_field="+challenge+"&recaptcha_response_field="+captcha1+"+"+captcha2;
				System.out.println(contenido);
				
				out.writeBytes(contenido);
				out.flush();
//				out.close();
				in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
				line = "";
				respuesta="";
				
				while((line=in.readLine())!=null)respuesta=respuesta+line; 
				System.out.println("P! me devuelve: "+HtmlEntities.decode(respuesta));
				if (!respuesta.contains("fue publicado satisfactoriamente") && (!respuesta.contains("status\":2,\"data\""))) JOptionPane.showMessageDialog( Main.this,HtmlEntities.decode(respuesta.substring(20,respuesta.length()-2)),"Info", JOptionPane.INFORMATION_MESSAGE );
				if (respuesta.contains("fue publicado satisfactoriamente")){
					if (timer2==null) timer2=new Timer();
					timer2.schedule(timerTask2, 60000);
					puedoPostear=false;
					JOptionPane.showMessageDialog( Main.this,"El post "+titulo.getText()+" fue publicado satisfactoriamente","Info", JOptionPane.INFORMATION_MESSAGE );
					System.out.println("El post fue publicado satisfactoriamente");
					comboCatP.setSelectedIndex(0);
					cook.clearCookies();
					out.close();
				}
				if (respuesta.contains("Ingresá el código que aparece en la imagen para continuar"))
					{
					
					System.out.println("Mando captcha luego de ingresar la captcha");
					}
				//if (respuesta.contains("\"status\":3")) JOptionPane.showMessageDialog( Main.this,"El captcha ingresado es incorrecto","Info", JOptionPane.INFORMATION_MESSAGE ); 
				in.close();
			}
		    
			}
			
		
		

		public  String preview() throws Exception {
			
			DataOutputStream out;
			String url="http://www.taringa.net/preview.php";

			//cook.clearCookies();
			String contenido;
					    
		    String line;
		    HttpURLConnection conn;
		    URL siteUrl;
		    String respuesta = "";
		    BufferedReader in;
		    
		    
		    login(config.getUsuario(),config.getContrasenia());
		   	   
			siteUrl = new URL(url);
			conn = (HttpURLConnection) siteUrl.openConnection();
			conn.setRequestMethod("POST");
			cook.writeCookies(conn, false);
			conn.setDoOutput(true);
			conn.setDoInput(true);
			out = new DataOutputStream(conn.getOutputStream());
			contenido="&titulo="+encode(truncarTitulo(titulo.getText()))+"&cuerpo="+encode(editor.getText()+propaganda);
			out.writeBytes(contenido);
			out.flush();
			in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
			line = "";
			while((line=in.readLine())!=null)
				respuesta=respuesta+line+"\n"; 
			
		
			
			out.close();
			in.close();
			
		    
		    return respuesta;
		    }
		
		
		
		private boolean existeBorrador(String str) {
			boolean resultado=false;
			if (br==null) {
				br= new Borrador(cook, config,this);
			}
			
			try {
				resultado= br.existeBorrador(str);
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			finally{
			return resultado;
			}
		}

		public void setBorradorId(String id) {
			borradorID=id;
		}
		
		public  void guardarBorradorOnlineT() throws Exception {
			String categoria="";
		categoria=Integer.toString(getCategoria());
			
			boolean checkCat = false;
		checkCat=checkCategoria();
			
			
			
			
			if(checkTitulo() && checkCat){
			
			if (borradorID.equals("") && !(existeBorrador(borradorID))) { //es un borrador nuevo
			
			
			System.out.println("Borrador nuevo");
			DataOutputStream out;
			String url="http://www.taringa.net/borradores-agregar.php";
			String contenido;
			String line;
		    HttpURLConnection conn;
		    URL siteUrl;
		    String respuesta;
		    BufferedReader in;
		    
		    
		    login(config.getUsuario(),config.getContrasenia());
		   	   
			siteUrl = new URL(url);
			conn = (HttpURLConnection) siteUrl.openConnection();
			conn.setRequestMethod("POST");
			cook.writeCookies(conn, false);
			conn.setDoOutput(true);
			conn.setDoInput(true);
			out = new DataOutputStream(conn.getOutputStream());
			contenido="titulo="+encode(truncarTitulo(titulo.getText()))+"&cuerpo="+encode(editor.getText()+propaganda)+"&tags="+encode(jTags.getText())+"&categoria="+categoria;
			out.writeBytes(contenido);
			out.flush();
		
			in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
			line = "";
			respuesta="";
			while((line=in.readLine())!=null)
				respuesta=respuesta+line; 
			System.out.println(respuesta);
			
							
			if (respuesta.contains("0:")){
				String [] campos=respuesta.split("0:");
				
				JOptionPane.showMessageDialog( Main.this,campos[1].trim(),"Guardar borrador", JOptionPane.INFORMATION_MESSAGE );
			}
			
			if (respuesta.contains(":1")){
				borradorID=getBorradorId(respuesta);
				
				
				JOptionPane.showMessageDialog( Main.this,"El borrador "+titulo.getText()+" fue guardado","Guardar borrador", JOptionPane.INFORMATION_MESSAGE );
				cook.clearCookies();
				
				
			}
			out.close();
			in.close();
			}
			else //es un borrador que ya existia
				/*
				 * Url: http://www.taringa.net/edicion2.php?id=IDDELPOST
Método: Post
Contenido post: key=userkey&id=IDDELPOST&borrador_id=&titulo=TITULO&cuerpo=POSTEDITADO&tags=TAGS&categoria=CATID&continue=Previsualizar&undefined=Guardar+a+Borradores

Respuesta: Nos devuelve el post en formato html

				 */
			{
				System.out.println("Modificando borrador");
				DataOutputStream out;
				String url="http://www.taringa.net/borradores-guardar.php";

				String contenido;
						    
			    String line;
			    HttpURLConnection conn;
			    URL siteUrl;
			    String respuesta;
			    BufferedReader in;
			    
			    
			    login(config.getUsuario(),config.getContrasenia());
			   	   
				siteUrl = new URL(url);
				conn = (HttpURLConnection) siteUrl.openConnection();
				conn.setRequestMethod("POST");
				cook.writeCookies(conn, false);
				conn.setDoOutput(true);
				conn.setDoInput(true);
				out = new DataOutputStream(conn.getOutputStream());
				contenido="titulo="+encode(titulo.getText())+"&cuerpo="+encode(editor.getText()+propaganda)+"&tags="+encode(jTags.getText())+"&categoria="+categoria+"&borrador_id="+borradorID;
				
				out.writeBytes(contenido);
				out.flush();
				in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
				line = "";
				respuesta="";
				while((line=in.readLine())!=null)
					respuesta=respuesta+line; 
				
				System.out.println(respuesta);
				
				if (respuesta.contains(":0")){
					String [] campos=respuesta.split("0:");
					
					JOptionPane.showMessageDialog( Main.this,campos[1].trim(),"Guardar borrador", JOptionPane.INFORMATION_MESSAGE );
				}
				if (respuesta.contains(":1")){
					JOptionPane.showMessageDialog( Main.this,"El borrador "+titulo.getText()+" fue guardado","Guardar borrador", JOptionPane.INFORMATION_MESSAGE );
					cook.clearCookies();
					
					
				}
				out.close();
				in.close();
			}
				
			
			}
			
			}
		
		public  void guardarBorradorOnlineP() throws Exception {
			String categoria="";
		categoria=Integer.toString(getCategoriaP());
			
			boolean checkCat = false;
		checkCat=checkCategoriaP();
			
			
			
			
			if(checkTitulo() && checkCat){
			
			if (borradorID.equals("") && !(existeBorrador(borradorID))) { //es un borrador nuevo
			
			
			System.out.println("Borrador nuevo");
			DataOutputStream out;
			String url="http://www.poringa.net/borradores-agregar.php";
			String contenido;
			String line;
		    HttpURLConnection conn;
		    URL siteUrl;
		    String respuesta;
		    BufferedReader in;
		    
		    
		    login(config.getUsuario(),config.getContrasenia());
		   	   
			siteUrl = new URL(url);
			conn = (HttpURLConnection) siteUrl.openConnection();
			conn.setRequestMethod("POST");
			cook.writeCookies(conn, false);
			conn.setDoOutput(true);
			conn.setDoInput(true);
			out = new DataOutputStream(conn.getOutputStream());
			contenido="titulo="+encode(truncarTitulo(titulo.getText()))+"&cuerpo="+encode(editor.getText()+propaganda)+"&tags="+encode(jTags.getText())+"&categoria="+categoria;
			out.writeBytes(contenido);
			out.flush();
		
			in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
			line = "";
			respuesta="";
			while((line=in.readLine())!=null)
				respuesta=respuesta+line; 
			System.out.println(respuesta);
			
							
			if (respuesta.contains("0:")){
				String [] campos=respuesta.split("0:");
				
				JOptionPane.showMessageDialog( Main.this,campos[1].trim(),"Guardar borrador", JOptionPane.INFORMATION_MESSAGE );
			}
			
			if (respuesta.contains(":1")){
				borradorID=getBorradorId(respuesta);
				
				
				JOptionPane.showMessageDialog( Main.this,"El borrador "+titulo.getText()+" fue guardado","Guardar borrador", JOptionPane.INFORMATION_MESSAGE );
				cook.clearCookies();
				
				
			}
			out.close();
			in.close();
			}
			else //es un borrador que ya existia
				/*
				 * Url: http://www.taringa.net/edicion2.php?id=IDDELPOST
Método: Post
Contenido post: key=userkey&id=IDDELPOST&borrador_id=&titulo=TITULO&cuerpo=POSTEDITADO&tags=TAGS&categoria=CATID&continue=Previsualizar&undefined=Guardar+a+Borradores

Respuesta: Nos devuelve el post en formato html

				 */
			{
				System.out.println("Modificando borrador");
				DataOutputStream out;
				String url="http://www.poringa.net/borradores-guardar.php";

				String contenido;
						    
			    String line;
			    HttpURLConnection conn;
			    URL siteUrl;
			    String respuesta;
			    BufferedReader in;
			    
			    
			    login(config.getUsuario(),config.getContrasenia());
			   	   
				siteUrl = new URL(url);
				conn = (HttpURLConnection) siteUrl.openConnection();
				conn.setRequestMethod("POST");
				cook.writeCookies(conn, false);
				conn.setDoOutput(true);
				conn.setDoInput(true);
				out = new DataOutputStream(conn.getOutputStream());
				contenido="titulo="+encode(titulo.getText())+"&cuerpo="+encode(editor.getText()+propaganda)+"&tags="+encode(jTags.getText())+"&categoria="+categoria+"&borrador_id="+borradorID;
				
				out.writeBytes(contenido);
				out.flush();
				in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
				line = "";
				respuesta="";
				while((line=in.readLine())!=null)
					respuesta=respuesta+line; 
				
				System.out.println(respuesta);
				
				if (respuesta.contains(":0")){
					String [] campos=respuesta.split("0:");
					
					JOptionPane.showMessageDialog( Main.this,campos[1].trim(),"Guardar borrador", JOptionPane.INFORMATION_MESSAGE );
				}
				if (respuesta.contains(":1")){
					JOptionPane.showMessageDialog( Main.this,"El borrador "+titulo.getText()+" fue guardado","Guardar borrador", JOptionPane.INFORMATION_MESSAGE );
					cook.clearCookies();
					
					
				}
				out.close();
				in.close();
			}
				
			
			}
			
			}
			
		private void bPostearActionPerformed(ActionEvent evt) throws Exception {
			
			
			switch (modo) {
			case 0: {
			System.out.println("Posteando en T!");
			if (checkPuedoPostear() && checkTitulo() && checkLongitud() && checkTags()&& checkCategoria()&& checkFuentes() && checkFuentesCorrectas() && !checkEsCrap()&&  checkRepost()) {
				getUserKey(config.getUsuario(),config.getContrasenia());
			int i =JOptionPane.showConfirmDialog(this,"¿Lo posteas ahora?","Subir post a T!",JOptionPane.YES_NO_OPTION);
			if(i==0){
				
			try {
				
				getUserKey(config.getUsuario(),config.getContrasenia());
				postearEnT(config.getUsuario(),config.getContrasenia(),false,"","");
			
			} catch (Exception e) {
				
			}
			}
			}break;
			}
			
			
			case 1: {
			System.out.println("Posteando en Comunidades");
			if (checkPuedoPostear() && checkTitulo() && checkLongitud() && checkComunidad()) {
				getUserKey(config.getUsuario(),config.getContrasenia());
			int i =JOptionPane.showConfirmDialog(this,"¿Lo posteas ahora?","Subir tema a la comunidad",JOptionPane.YES_NO_OPTION);
			if(i==0){
				
			try {
				
				getUserKey(config.getUsuario(),config.getContrasenia());
				
				postearEnComu(config.getUsuario(),config.getContrasenia(),listaComunidades.get(comboComu.getSelectedIndex()-1)[0]);
				
			
			} catch (Exception e) {
				
			}
			}
		}break;
		}
			
			case 2:  {
				System.out.println("Posteando en P!");
				if (checkPuedoPostear() && checkTitulo() && checkLongitud() && checkTags()&& checkCategoriaP()&& checkFuentes() && checkFuentesCorrectas() && !checkEsCrap()&&  checkRepostP()) {
					getUserKey(config.getUsuario(),config.getContrasenia());
				int i =JOptionPane.showConfirmDialog(this,"¿Lo posteas ahora?","Subir post a P!",JOptionPane.YES_NO_OPTION);
				if(i==0){
					
				try {
					
					getUserKey(config.getUsuario(),config.getContrasenia());
					postearEnP(config.getUsuario(),config.getContrasenia(),false,"","");
				
				} catch (Exception e) {
					
				}
				}
				}break;
				}
			}
			
			
			
			/*
			if (modo.equals("poringa")) {// seleccionado = postear en T!

				System.out.println("Posteando en P!");
				
				if (checkPuedoPostear() && checkTitulo() && checkLongitud() && checkTags()&& checkCategoriaP()&& !checkCrap()&& checkRepostP()) {
					key=getUserKey(config.getUsuario(),config.getContrasenia());
				int i =JOptionPane.showConfirmDialog(this,"¿Lo posteas ahora?","Subir post a P!",JOptionPane.YES_NO_OPTION);
				if(i==0){
					
				try {
					
					key=getUserKey(config.getUsuario(),config.getContrasenia());
					postear(config.getUsuario(),config.getContrasenia(),false,"","");
				
				} catch (Exception e) {
					
				}
				}
			}
				}
			*/
			
			
			
		}

		private JPanel getOpciones() {
			if(opciones == null) {
				opciones = new JPanel();
				TableLayout opcionesLayout = new TableLayout(new double[][] {{TableLayout.FILL, TableLayout.FILL, TableLayout.FILL, TableLayout.FILL, TableLayout.FILL}, {28.0, 35.0, 41.0, TableLayout.FILL}});
				opcionesLayout.setHGap(5);
				opcionesLayout.setVGap(5);
				opciones.setLayout(opcionesLayout);
			//	opciones.setBackground(new java.awt.Color(255,255,255));
				opciones.add(getJTags(), "0,0,4,0,f,f");
			}
			return opciones;
		}
		
		private JPanel getJPanel1() {
			if(jPanel1 == null) {
				jPanel1 = new JPanel();
				TableLayout jPanel1Layout = new TableLayout(new double[][] {{TableLayout.FILL}, {TableLayout.FILL, TableLayout.FILL, TableLayout.FILL, TableLayout.FILL, TableLayout.FILL, TableLayout.FILL, TableLayout.MINIMUM}});
				jPanel1Layout.setHGap(5);
				jPanel1Layout.setVGap(5);
				jPanel1.setLayout(jPanel1Layout);
				//jPanel1.setBackground(new java.awt.Color(255,255,255));
				
				jPanel1.add(getSalir(), "0,5,c,f");
				jPanel1.add(getRangos(), "0, 4, r, f");
				jPanel1.add(getSticky(), "0, 0");
				jPanel1.add(getRadioRangos(), "0, 4, l, f");
				jPanel1.add(getRadioNadie(), "0, 3");
				jPanel1.add(getRadioTodos(), "0, 2");
				jPanel1.add(getCheckSoloRegistrados(), "0, 1");
				getComentariosGroup();
				comentariosGroup.add(radioNadie);
				comentariosGroup.add(radioTodos);
				comentariosGroup.add(radioRangos);
			}
			return jPanel1;
		}
		
		
		

		private OnOffButton getPegadoInt() {
			if(pegadoInt == null) {
				pegadoInt = new OnOffButton();
				pegadoInt.setText("On/Off");
				pegadoInt.setSize(25, 25);
				pegadoInt.setPreferredSize(new java.awt.Dimension(55, 20));
				pegadoInt.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						pegadoIntActionPerformed(evt);
					}
				});
			}
			return pegadoInt;
		}

		private JLabel getJLabel7() {
			if(jLabel7 == null) {
				jLabel7 = new JLabel();
				jLabel7.setText("Pegado Inteligente");
				jLabel7.setFont(new java.awt.Font("Arial",0,12));
				jLabel7.setPreferredSize(new java.awt.Dimension(120, 14));
				jLabel7.setSize(120, 14);
			}
			return jLabel7;
		}
		
		private JLabel getJLabel8() {
			if(jLabel8 == null) {
				jLabel8 = new JLabel();
				jLabel8.setText("Previsualizar online");
				jLabel8.setFont(new java.awt.Font("Arial",0,12));
				jLabel8.setBounds(-17, 0, 75, 35);
				jLabel8.setPreferredSize(new java.awt.Dimension(120, 14));
			}
			return jLabel8;
		}

		private JProgressBar getProgressBar() {
			if (progressBar == null) {
				progressBar = new JProgressBar();
				opciones.add(getbPostear(), "3, 2, 4, 2, c, f");
				opciones.add(getPreview(), "0, 2, 1, 2, c, f");
				opciones.add(getCheckRecopilacion(), "0,1,2,1,l,f");
				opciones.add(getJButton1(), "2,1,4,1,r,c");
				progressBar.setValue(0);
				progressBar.setStringPainted(true);
				progressBar.setSize(150, 10);
				progressBar.setPreferredSize(new java.awt.Dimension(150, 13));
				progressBar.setEnabled(false);
				progressBar.setVisible(false);
				progressBar.setForeground(colorNaranja);
			}
			return progressBar;
		}
		private JLabel getLblChars() {
			if(lblChars == null) {
				lblChars = new JLabel();
				lblChars.setText("0");
				lblChars.setPreferredSize(new java.awt.Dimension(82, 25));
				lblChars.setFont(new java.awt.Font("Arial",0,12));
				lblChars.setForeground(colorNegro);
			}
			return lblChars;
		}

		private OnOffButton getPrevOnline() {
			if(prevOnline == null) {
				prevOnline = new OnOffButton();
				prevOnline.setText("On/Off");
				prevOnline.setSize(25, 25);
				prevOnline.setPreferredSize(new java.awt.Dimension(55, 20));
			}
			return prevOnline;
		}
		
		private JMenuItem getNuevo() {
			if(nuevo == null) {
				nuevo = new JMenuItem();
				nuevo.setText("Nuevo post");
				nuevo.setBounds(118, 21, 83, 22);
				//nuevo.setBackground(new java.awt.Color(255,255,255));
				nuevo.setFont(new java.awt.Font("Arial",0,12));
				nuevo.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						nuevoActionPerformed(evt);
					}
				});
			}
			return nuevo;
		}
		
		private void nuevoActionPerformed(ActionEvent evt) {
			int i =JOptionPane.showConfirmDialog(this,"¿Querés crear un nuevo post?\n Los datos se perderán","Nuevo post",JOptionPane.YES_NO_OPTION);
			if(i==0){
				nuevoPost();
			}
		}
		
				
	

		public void setTitulo(String str) {
			titulo.setText(str);
		}
		
		public void setCuerpo(String str) {
			editor.setText(str);
		}
		
		public void setTags(String str) {
		jTags.setText(str);
		}

		public void setPrivado(boolean b) {
			checkSoloRegistrados.setSelected(b);
		}
		
		public void setSin_comentarios(boolean b) {
			radioNadie.setSelected(b);
		}
		
		
		private int getCatNum(String str){
			int num=99;
			if (!(str.equals(""))) num=Integer.parseInt(str);
			for (int i=0;i<categoriasNum.length;i++){
				if(categoriasNum[i]==num) 
						return i;
				
				
			}
			return 0;
		}
		private int getCatNumP(String str){
			int num=99;
			if (!(str.equals(""))) num=Integer.parseInt(str);
			for (int i=0;i<categoriasNumP.length;i++){
				if(categoriasNumP[i]==num) 
						return i;
				
				
			}
			return 0;
		}
		public void setCategoria(String str) {
			comboCat.setSelectedIndex(getCatNum(str));
		}
		
		public void setComunidad(String str) {
			comboComu.setSelectedIndex(getIndexComboComu(str)+1);
		}
		
		public void setCategoriaP(String str) {
			comboCatP.setSelectedIndex(getCatNumP(str));
		}
		
		private JMenu getBorradores() {
			if(Borradores == null) {
				Borradores = new JMenu();
				Borradores.setText("Borradores");
			//	Borradores.setBackground(new java.awt.Color(255,255,255));
				Borradores.setFont(arialPlain12);
			//	Borradores.setForeground(new java.awt.Color(0,0,0));
				Borradores.add(getAbrirB());
				Borradores.add(getGuardaBorrador());
				Borradores.add(getJSeparator6());
				Borradores.add(getVer());
			}
			return Borradores;
		}
		
		private JMenuItem getVer() {
			if(ver == null) {
				ver = new JMenuItem();
				ver.setText("Ver borradores en Taringa!");
			//	ver.setForeground(new java.awt.Color(0,0,0));
				ver.setFont(new java.awt.Font("Arial",0,12));
			//	ver.setBackground(new java.awt.Color(255,255,255));
				ver.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						verActionPerformed(evt);
					}
				});
			}
			return ver;
		}
		
		private JSeparator getJSeparator6() {
			if(jSeparator6 == null) {
				jSeparator6 = new JSeparator();
				jSeparator6.setBounds(138, 21, 70, 8);
			}
			return jSeparator6;
		}
		
		private void verActionPerformed(ActionEvent evt) {
			verBorradores();
			
	    	
		}
		
		private void verBorradores() {
			try {
				if (login(config.getUsuario(),config.getContrasenia())) {
					if (br==null) {
						br= new Borrador(cook, config,this);	
					}
		    		   	
					if (modo==0) {
						br.getBorradoresOnlineT();
						br.mostrarBorradoresT();
					}
					
					if (modo==2) {
						br.getBorradoresOnlineP();
						br.mostrarBorradoresP();
					}
					if (modo==1) {
						br.getBorradoresOnlineC();
						br.mostrarBorradoresC();
					}
				}
				}catch (Exception e) {
					JOptionPane.showMessageDialog( Main.this,"No se pudo establecer la conexión con el servidor.\n Chequea tu conexión a internet","Ups", JOptionPane.ERROR_MESSAGE );
					
				}
		}

				
		private void btnFuentesActionPerformed(ActionEvent evt) {
		
			
			fuentes.setLocationRelativeTo(this);

			
			fuentes.setVisible(true);
			fuentes.setFocus();
			
			
			/*mostrarEsperar();
			Thread hilo = new Thread ( new Runnable()
			{
			public void run()
			{
				try {
					guardarBorradorOnline();
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			
			}
			});
			hilo.start();
		
			*/
			

			
			
			}

		private JPanel getJPanel3() {
			if(jPanel3 == null) {
				jPanel3 = new JPanel();
				//jPanel3.setBackground(new java.awt.Color(255,255,255));

				jPanel3.add(getJLabel8());
				jPanel3.add(getPrevOnline());
				jPanel3.add(getJLabel7());
				jPanel3.add(getPegadoInt());
				jPanel3.add(getLater());
				jPanel3.add(getJDropDownButton1());
				jPanel3.add(getProgressBar());
				jPanel3.add(getChars());
				jPanel3.add(getLblChars());

			}
			return jPanel3;
		}
		
		private JLabel getChars() {
			if(chars == null) {
				chars = new JLabel();
				chars.setText("Caracteres:");
				chars.setFont(new java.awt.Font("Arial",0,12));
				chars.setPreferredSize(new java.awt.Dimension(76, 15));
			}
			return chars;
		}



private void mostrarAcercaDe() {
	if (acerca==null) acerca = new AcercaDe(this);
	acerca.setLocationRelativeTo(this);
	acerca.setVisible(true);
	
}




private JMenuItem getJMenuItem5() {
	if(jMenuItem5 == null) {
		jMenuItem5 = new JMenuItem();
		jMenuItem5.setText("Ayuda (online)");
		jMenuItem5.setBounds(163, 20, 54, 23);
		jMenuItem5.setFont(new java.awt.Font("Arial",0,12));
		jMenuItem5.setToolTipText("Ayuda de PosT!NGA");
		jMenuItem5.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				jMenuItem5ActionPerformed(evt);
			}
		});
	}
	return jMenuItem5;
}


public void setFuentesInfo(ArrayList<String> array) {
	fuentesInfo=(ArrayList<String>) array.clone();
	/*Iterator<String> itr = fuentesInfo.iterator();
    while (itr.hasNext()) {
      String element = itr.next();
      System.out.print(element + " ");
    }*/
	
}


private void jMenuItem5ActionPerformed(ActionEvent evt) {
	abrirWeb(ayudaPostinga);
}
private JPanel getJPanel5() {
	if(postearEnPanel == null) {
		postearEnPanel = new JPanel();
		postearEnPanel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
		postearEnPanel.add(getIndicador());
		postearEnPanel.add(getTradio());
		postearEnPanel.add(getPradio());
		postearEnPanel.add(getCradio());

	}
	return postearEnPanel;
}

private void modoComu() {
	ver.setText("Ver borradores en Comunidades");
	cat.setText("Comunidad");
	comboCat.setVisible(false);
	comboCatP.setVisible(false);
	comboComu.setVisible(true);
	jTags.setEnabled(false);
	reloadComu.setVisible(true);
	Cradio.setFont(arialBold12);
	Tradio.setFont(arialPlain12);
	Pradio.setFont(arialPlain12);
	modo=1;
	rangos.setEnabled(false);
	radioRangos.setEnabled(false);
	radioTodos.setSelected(true);
	/*Cradio.setBackground(colorVerde);
	Pradio.setBackground(new java.awt.Color(238,238,238));
	Tradio.setBackground(new java.awt.Color(238,238,238));
	Pradio.setForeground(colorNegro);
	Tradio.setForeground(colorNegro);
	Cradio.setForeground(colorNegro);*/
	indicador.setBackground(colorVerde);
	checkSoloRegistrados.setText("Seguir este tema");
	btnFuentes.setEnabled(false);
	checkRecopilacion.setEnabled(false);
	sticky.setVisible(true);
}


private void modoPostT() {
	ver.setText("Ver borradores en Taringa!");
	cat.setText("Categoria");
	comboComu.setVisible(false);
	comboCat.setVisible(true);
	comboCatP.setVisible(false);
	jTags.setEnabled(true);
	sticky.setVisible(false);
	reloadComu.setVisible(false);
	
	
	Tradio.setFont(arialBold12);
	Cradio.setFont(arialPlain12);
	Pradio.setFont(arialPlain12);

	modo=0;
	Tradio.setSelected(true);
	rangos.setEnabled(true);
	/*Tradio.setBackground(colorAzul);
	Pradio.setBackground(new java.awt.Color(238,238,238));
	Cradio.setBackground(new java.awt.Color(238,238,238));
	Pradio.setForeground(colorNegro);
	Cradio.setForeground(colorNegro);
	Tradio.setForeground(colorBlanco);*/
	indicador.setBackground(colorAzul);
	radioRangos.setEnabled(true);
	checkSoloRegistrados.setText("Solo usuarios registrados");
	btnFuentes.setEnabled(true);
	checkRecopilacion.setEnabled(true);
}

private void modoPostP() {
	Pradio.setFont(arialBold12);
	Cradio.setFont(arialPlain12);
	Tradio.setFont(arialPlain12);

	ver.setText("Ver borradores en Poringa!");
	cat.setText("Categoria");
	comboComu.setVisible(false);
	comboCat.setVisible(false);
	comboCatP.setVisible(true);
	jTags.setEnabled(true);
	checkSoloRegistrados.setText("Solo usuarios registrados");
	rangos.setEnabled(false);
	radioRangos.setEnabled(false);
	radioTodos.setSelected(true);
	btnFuentes.setEnabled(true);
	checkRecopilacion.setEnabled(true);
	modo=2;
	sticky.setVisible(false);
	reloadComu.setVisible(false);
	/*Pradio.setBackground(colorRojo);
	Tradio.setBackground(new java.awt.Color(238,238,238));
	Cradio.setBackground(new java.awt.Color(238,238,238));
	Tradio.setForeground(colorNegro);
	Cradio.setForeground(colorNegro);
	Pradio.setForeground(colorBlanco);*/
	indicador.setBackground(colorRojo);
}

public String getContrasenia() {
	return config.getContrasenia();
}
public String getUsuario() {
	return config.getUsuario();
}





private  void postearEnComu(String usuario, String pass,String comu) throws Exception {
	
	/* formato del POST
	 * key=112fb4&borrador_id=&comid=39405&titulo=prueba&cuerpo=%5Bcolor%3Dgreen%5D%5B%2Fcolor%5D&tags=a%2Cb%2Cc%2Cd
	 * 
	 * http://www.taringa.net/comunidades/agregando/

	 */
	DataOutputStream out;
	System.out.println("Postear en Comu");
	String agregar="http://www.taringa.net/comunidades/agregando/";

	cook.clearCookies();
	String contenido;
	
    String line;
    HttpURLConnection conn;
    URL siteUrl;
    String respuesta;
    BufferedReader in;
    
    login(usuario,pass);
    System.out.println("URL: "+comu);
    
	siteUrl = new URL(agregar);
	conn = (HttpURLConnection) siteUrl.openConnection();
	conn.setRequestMethod("POST");
	cook.writeCookies(conn, false);
	conn.setDoOutput(true);
	conn.setDoInput(true);
	out = new DataOutputStream(conn.getOutputStream());
	
	contenido="key="+key+"&borrador_id=&comid="+getComunidadID(comu)+"&titulo="+encode(titulo.getText())+"&cuerpo="+encode(editor.getText()+propaganda)+"&tags=a%2Cb%2Cc%2Cd"+getComentariosStatusComu();
	System.out.println(contenido);
	out.writeBytes(contenido);
	out.flush();
	in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
	line = "";
	respuesta="";
	while((line=in.readLine())!=null)respuesta=respuesta+line; 
	System.out.println(respuesta);
	if (respuesta.contains("CHAN!!")) JOptionPane.showMessageDialog( Main.this,"Código de seguridad incorrecto","Info", JOptionPane.INFORMATION_MESSAGE ); 
	if (respuesta.contains("Tu rango no te permite realizar esta")) JOptionPane.showMessageDialog( Main.this,"Tu rango no te permite realizar esta operación","Info", JOptionPane.INFORMATION_MESSAGE );	
	
	if (respuesta.contains("El nuevo tema fue agregado a la comunidad")){
		if (timer2==null) timer2=new Timer();
		timer2.schedule(timerTask2, 60000);
		puedoPostear=false;
		JOptionPane.showMessageDialog( Main.this,"El tema "+truncarTitulo(titulo.getText())+" fue agregado a la comunidad","Info", JOptionPane.INFORMATION_MESSAGE );
		cook.clearCookies();
		comboCat.setSelectedIndex(0);
		
	}
	in.close();
	out.close();

	//El nuevo tema fue agregado a la comunidad
		
	}

	private JRadioButton getTradio() {
		if(Tradio == null) {
			Tradio = new JRadioButton();
			Tradio.setText("T!");
			selector.add(Tradio);
			Tradio.setFont(arialPlain12);

			Tradio.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent evt) {
					TradioActionPerformed(evt);
				}
			});
		}
		return Tradio;
	}
	
	private JRadioButton getPradio() {
		if(Pradio == null) {
			Pradio = new JRadioButton();
			Pradio.setText("P!");
			selector.add(Pradio);
			Pradio.setFont(arialPlain12);
			Pradio.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent evt) {
					PradioActionPerformed(evt);
				}
			});
		}
		return Pradio;
	}
	
	private JRadioButton getCradio() {
		if(Cradio == null) {
			Cradio = new JRadioButton();
			Cradio.setText("Comu");
			selector.add(Cradio);
			Cradio.setFont(arialPlain12);
			Cradio.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent evt) {
					CradioActionPerformed(evt);
				}
			});
		}
		return Cradio;
	}
	
	private void TradioActionPerformed(ActionEvent evt) {
		modoPostT();
	}
	
	private void CradioActionPerformed(ActionEvent evt) {
		modoComu();
	}
	
	private void PradioActionPerformed(ActionEvent evt) {
		modoPostP();	
	}

	
	//respuesta=comentando&temaid=1807153&key=112fb4

	
	public void setChallenge(String chal) {
		
		challenge=chal;
		
	}
	
	public void reportarBug(String bug) throws Exception {
		DataOutputStream out;
		String jv,os;
		String agregar="http://www.taringa.net/comunidades/respuesta.php";
		jv="Version de JRE: "+System.getProperty("java.version");
		os="Sistema: "+System.getProperty("os.name")+"\nVersion del SO: "+System.getProperty("os.version")+"\nArquitectura: "+System.getProperty("os.arch");
		
		//cook.clearCookies();
		String contenido;
		
	    String line;
	    HttpURLConnection conn;
	    URL siteUrl;
	    String respuesta;
	    BufferedReader in;
	    login(config.getUsuario(),config.getContrasenia());
	    siteUrl = new URL(agregar);
		conn = (HttpURLConnection) siteUrl.openConnection();
		conn.setRequestMethod("POST");
		cook.writeCookies(conn, false);
		conn.setDoOutput(true);
		conn.setDoInput(true);
		out = new DataOutputStream(conn.getOutputStream());
		contenido="respuesta="+encode(jv+"\n"+os+"\n"+"Version de PosT!NGA: "+version+"\n"+bug)+"&temaid=1807153&key="+key+"&mostrar_resp=false";
		System.out.println("BUG: "+contenido);
		
		out.writeBytes(contenido);
		out.flush();
		
		in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
		line = "";
		respuesta="";
		while((line=in.readLine())!=null)respuesta=respuesta+line;
		//System.out.println(respuesta);
		/*
		 *POsibles respuestas:
		 *0: No puedes realizar tantas acciones en tan poco tiempo. Vuelve a intentarlo en unos instantes
		 *1: Tu respuesta fue agregada satisfactoriamente 
		 * */
		
		 
		if (respuesta.contains("1: ")) {
			
			JOptionPane.showMessageDialog( Main.this,"El bug fue reportado en la conunidad de PosT!NGA exitosamente","Info", JOptionPane.INFORMATION_MESSAGE );	
		}
		
		else if (respuesta.contains("0: ")) { 
			JOptionPane.showMessageDialog( Main.this,"No puedes realizar tantas acciones en tan poco tiempo. Vuelve a intentarlo en unos instantes","Info", JOptionPane.INFORMATION_MESSAGE );	
				
		} else JOptionPane.showMessageDialog( Main.this,"Ocurrio un error al intentar enviar el bug. Proba en unos instantes","Info", JOptionPane.INFORMATION_MESSAGE );
		
		in.close();
		out.close();
	}
	
	private JButton getJButton1() {
		if(btnFuentes == null) {
			btnFuentes = new JButton();
			btnFuentes.setText("Fuentes de Informacion");
			btnFuentes.setFont(new java.awt.Font("Arial",0,12));
			btnFuentes.setIcon(new ImageIcon(getClass().getClassLoader().getResource("app/addT.png")));
			btnFuentes.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent evt) {
					btnFuentesActionPerformed(evt);
				}
			});
		}
		return btnFuentes;
	}
	
	private JCheckBox getCheckRecopilacion() {
		if(checkRecopilacion == null) {
			checkRecopilacion = new JCheckBox();
			checkRecopilacion.setText("Contenido Original o Recop.");
			checkRecopilacion.setFont(new java.awt.Font("Arial",0,12));
			checkRecopilacion.setPreferredSize(new java.awt.Dimension(183, 21));
		}
		return checkRecopilacion;
	}
	
	public void setCantFuentes(int cant) {
		if (cant!=0) btnFuentes.setText("Fuentes de informacion ("+String.valueOf(cant)+")");
		else btnFuentes.setText("Fuentes de informacion"); 
			
	}

	
	public String getKey() {
		return key;
	}
		
	private String truncate(String value, int length)
	{
	  if (value != null && value.length() > length)
	    value = value.substring(0, length);
	  return value;
	}
	
	public String validarFuente(String fuente) throws Exception {
	    /*
	     * Arreglo con
	     * 1: Info
	     * 2: URL
	     * 3: URL del icono
	     * 
	     */
		
	       login(config.getUsuario(),config.getContrasenia());
	       HttpURLConnection conn;
	     
		   URL siteUrl = new URL("http://www.taringa.net/ajax/source/data-add");
		   conn = (HttpURLConnection) siteUrl.openConnection();
		conn.setRequestMethod("POST");
		cook.addCookie("canIHaveBetaForTaringaV5Plskthx", "79f11ff2c8fab868d73d72269119f3b8",false);
		cook.viewAllCookies();
		cook.writeCookies(conn, false);
		conn.setDoOutput(true);
		conn.setDoInput(true);
		DataOutputStream out = new DataOutputStream(conn.getOutputStream());
		out.writeBytes("url="+encode(fuente));
		out.flush();
		out.close();
		BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
		String line = "";
		
		line=in.readLine();
			
		in.close();
		return armarDatos(line);
		
		
	}
	
	private boolean agregarFuentes() throws Exception {
		
	    String respuesta="";
		
		
		for (int i=0;i<fuentesInfo.size();i++) {
			respuesta=validarFuente(fuentesInfo.get(i));
			System.out.println(respuesta);
			if (respuesta.equals("error")) return false;
			fuentesDeInfo=fuentesDeInfo+"&sources_url_id%5B%5D="+respuesta;
		}
		
		System.out.println("FUENTES DE INFORMACION: "+fuentesDeInfo);
		
	return true;
	}
	
	private String armarDatos(String str) throws IOException {
	System.out.println(str);
		String[] tmp= str.split(",");
		if (tmp[0].contains("status\":1")) {
			
		tmp[1]=tmp[1].substring(14,tmp[1].length()-1);
		tmp[2]=tmp[2].substring(7,tmp[2].length()-1).replaceAll("\\/","").replace('\\', '/');
		tmp[3]=tmp[3].substring(9,tmp[3].length()-1).replaceAll("\\\\n","");
		tmp[4]=tmp[4].substring(11,tmp[4].length()-3).replaceAll("\\/","").replace('\\', '/');;

		return tmp[1]; 
		
	}
		//else JOptionPane.showMessageDialog(null,tmp[1].substring(8, tmp[1].length()-2), "Ups!", JOptionPane.INFORMATION_MESSAGE);
		
		return "error";
		
	}
	
	private String getComunidadID(String com) throws Exception {
		 String nextLine="";
		 
		 URL url = null;
		 String url2="http://www.taringa.net"+com;
		 
	       
	       URLConnection urlConn = null;
	       InputStreamReader  inStream = null;
	       BufferedReader buff = null;
	     
	          // Create the URL obect that points
	          // at the default file index.html
	          url  = new URL(url2);
	        
	          urlConn = url.openConnection();
	         
	          cook.writeCookies(urlConn, false);
	          inStream = new InputStreamReader( 
	                           urlConn.getInputStream());
	           buff= new BufferedReader(inStream);
	        
	       // Read and print the lines from index.html
	        while (true){
	            nextLine =buff.readLine();  
	            if (nextLine !=null){
	            
	            	if (nextLine.contains("comid:")) {
	            		int a,b;
	            		a=nextLine.indexOf("comid: ")+8;
	            		b=nextLine.indexOf(",",a+1);
	            		return nextLine.substring(a,b-1);
	            		
	            	}
	
	            }
	            
	            
	        }
			
	       }


	public void setAutoTimer(int timer) {
		if (timer!=0) autoTimer=timer;
	}
	
	private JLabel getIndicador() {
		if(indicador == null) {
			indicador = new JLabel();
			indicador.setPreferredSize(new java.awt.Dimension(4, 30));
			indicador.setForeground(new java.awt.Color(0,0,255));
			indicador.setOpaque(true);
			indicador.setSize(16, 5);
		}
		return indicador;
	}
	
	private JComboBox getRangos() {
		if(rangos == null) {
	
			ComboBoxModel rangosModel = 
					new DefaultComboBoxModel(
							new String[] { "Flamer", "Inexperto","Iniciado","Aprendiz","Amateur","Regular","Experto","Avanzado","Elite","Silver","Gold","Platinum" });
			rangos = new JComboBox();
			rangos.setModel(rangosModel);
			rangos.setFont(new java.awt.Font("Arial",0,12));
			rangos.setSelectedIndex(2);
		}
		return rangos;
	}
	
	private JRadioButton getRadioRangos() {
		if(radioRangos == null) {
			radioRangos = new JRadioButton();
			radioRangos.setText("Mayores que");
			radioRangos.setFont(new java.awt.Font("Arial",0,12));
		}
		return radioRangos;
	}
	
	private JRadioButton getRadioNadie() {
		if(radioNadie == null) {
			radioNadie = new JRadioButton();
			radioNadie.setText("Nadie puede comentar");
			radioNadie.setFont(new java.awt.Font("Arial",0,12));
		}
		return radioNadie;
	}
	
	private JRadioButton getRadioTodos() {
		if(radioTodos == null) {
			radioTodos = new JRadioButton();
			radioTodos.setText("Todos pueden comentar");
			radioTodos.setSelected(true);
			radioTodos.setFont(new java.awt.Font("Arial",0,12));
		}
		return radioTodos;
	}
	
	private JCheckBox getCheckSoloRegistrados() {
		if(checkSoloRegistrados == null) {
			checkSoloRegistrados = new JCheckBox();
			checkSoloRegistrados.setText("Solo usuarios registrados");
			checkSoloRegistrados.setFont(new java.awt.Font("Arial",0,12));
		}
		return checkSoloRegistrados;
	}
	
	private ButtonGroup getComentariosGroup() {
		if(comentariosGroup == null) {
			comentariosGroup = new ButtonGroup();
		}
		return comentariosGroup;
	}



	private String getComentariosStatusComu() {
		//POST &follow=on&cerrado=on&sticky=on
		String temp="";
		
		if (checkSoloRegistrados.isSelected()) temp="&follow=on";
		if (radioNadie.isSelected()) temp=temp+"&cerrado=on";		
		if (sticky.isSelected()) temp=temp+"&sticky=on";
		return temp;
		
	}
	
	private String getComentariosStatus() {
		/*
		todos:&sin_comentarios=0&sin_comentarios_rango=12
		nadie:&sin_comentarios=1&sin_comentarios_rango=12
		0 flamer: &sin_comentarios=2&sin_comentarios_rango=10
		1 inexperto:&sin_comentarios=2&sin_comentarios_rango=12
		2 iniciado 
		2 Aprendiz:&sin_comentarios=2&sin_comentarios_rango=13
		3 Amateur:&sin_comentarios=2&sin_comentarios_rango=14
		4 Regular:&sin_comentarios=2&sin_comentarios_rango=15
		5 Experto:&sin_comentarios=2&sin_comentarios_rango=16
		6 Avanzado:&sin_comentarios=2&sin_comentarios_rango=17
		7 Elite:&sin_comentarios=2&sin_comentarios_rango=18
		8 Silver:&sin_comentarios=2&sin_comentarios_rango=19
		9 gold: &sin_comentarios=2&sin_comentarios_rango=20
		10 platinum:&sin_comentarios=2&sin_comentarios_rango=21
		 * */
		
		String privado="";
		if (checkSoloRegistrados.isSelected()) privado="&privado=on";
		int seleccionado=rangos.getSelectedIndex();
		if (radioTodos.isSelected()) return privado+"&sin_comentarios=0&sin_comentarios_rango=12";
		else if (radioNadie.isSelected()) return privado+"&sin_comentarios=1&sin_comentarios_rango=12";
		else switch (seleccionado) {
		case 0: return privado+"&sin_comentarios=2&sin_comentarios_rango=10";
		case 1: return privado+"&sin_comentarios=2&sin_comentarios_rango=11";
		case 2: return privado+"&sin_comentarios=2&sin_comentarios_rango=12";
		case 3: return privado+"&sin_comentarios=2&sin_comentarios_rango=13";
		case 4: return privado+"&sin_comentarios=2&sin_comentarios_rango=14";
		case 5: return privado+"&sin_comentarios=2&sin_comentarios_rango=15";
		case 6: return privado+"&sin_comentarios=2&sin_comentarios_rango=16";
		case 7: return privado+"&sin_comentarios=2&sin_comentarios_rango=17";
		case 8: return privado+"&sin_comentarios=2&sin_comentarios_rango=18";
		case 9: return privado+"&sin_comentarios=2&sin_comentarios_rango=19";
		case 10: return privado+"&sin_comentarios=2&sin_comentarios_rango=20";
		case 11: return privado+"&sin_comentarios=2&sin_comentarios_rango=21";
		default: return privado+"";
		}
			
		


	
	}
	
	public int getModo() {
		return modo;
		}
	
	private JCheckBox getSticky() {
		if(sticky == null) {
			sticky = new JCheckBox();
			sticky.setText("Sticky");
			sticky.setFont(new java.awt.Font("Arial",0,12));
		}
		return sticky;
	}

	
	
	private void leerXML(File file) {
		try {
			  
			  DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
			  DocumentBuilder db = dbf.newDocumentBuilder();
			  org.w3c.dom.Document doc = db.parse(file);
			  doc.getDocumentElement().normalize();
			  System.out.println("Root element " + doc.getDocumentElement().getNodeName());
			  Node nodo= doc.getDocumentElement();
			  NodeList listaNodos=nodo.getChildNodes();
			  Node nTitulo=listaNodos.item(0);
			  Node nCuerpo=listaNodos.item(1);
			  Node nTags=listaNodos.item(2);
			  Node nCategoria=listaNodos.item(3);
			  Node nFuentes=listaNodos.item(4);
			  Node nPropio=listaNodos.item(5);
			  Node nTipo=listaNodos.item(6);
			  NodeList listaFuentes = nFuentes.getChildNodes();
			  
			 
			  
			  
			 titulo.setText(nTitulo.getTextContent());
			 editor.setText(nCuerpo.getTextContent());
			 jTags.setText(nTags.getTextContent());
			 if (nTipo.getTextContent().equals("0")){ 
				 Tradio.setSelected(true);
				 modoPostT();
				 comboCat.setSelectedIndex(getCatNum(nCategoria.getTextContent()));
				 }
			 if (nTipo.getTextContent().equals("1")) { 
				 Cradio.setSelected(true);
				 modoComu();
				 }
			 if (nTipo.getTextContent().equals("2")) { 
				 Pradio.setSelected(true); 
				 modoPostP(); 
				 comboCatP.setSelectedIndex(getCatNumP(nCategoria.getTextContent()));
				 }
			 if (nPropio.getTextContent().equals("SI")) checkRecopilacion.setSelected(true);
			 else  checkRecopilacion.setSelected(false);
			 
			 fuentes.setFuente(1,listaFuentes.item(0).getTextContent());
			 fuentes.setFuente(2,listaFuentes.item(1).getTextContent());
			 fuentes.setFuente(3,listaFuentes.item(2).getTextContent());
			 fuentes.setFuente(4,listaFuentes.item(3).getTextContent());
			 fuentes.setFuente(5,listaFuentes.item(4).getTextContent());
			 fuentes.cerrar();
			 
			  
			  } catch (Exception e) {
			    e.printStackTrace();
			  }
			 }
	
	
	
	
	
	private org.w3c.dom.Document guardarXML() {
		 
		String [] fInfo = new String[5];
		fInfo[0]=fuentes.getFuenteInfo(1);
		fInfo[1]=fuentes.getFuenteInfo(2);
		fInfo[2]=fuentes.getFuenteInfo(3);
		fInfo[3]=fuentes.getFuenteInfo(4);
		fInfo[4]=fuentes.getFuenteInfo(5);
		
		System.out.println(fInfo[0]);
		System.out.println(fInfo[1]);
		System.out.println(fInfo[2]);
		System.out.println(fInfo[3]);
		System.out.println(fInfo[4]);
		
		try {
			 
				DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
				DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
		 
				// root elements
				org.w3c.dom.Document doc = docBuilder.newDocument();
				Element post = doc.createElement("post");
				doc.appendChild(post);
		 
				// staff elements
				Element titulo = doc.createElement("titulo");
				post.appendChild(titulo);
				
				Element cuerpo = doc.createElement("cuerpo");
				post.appendChild(cuerpo);
				
				Element tags = doc.createElement("tags");
				post.appendChild(tags);
				
				Element categoria = doc.createElement("categoria");
				post.appendChild(categoria);
				
				Element fuentes = doc.createElement("fuentes");
				post.appendChild(fuentes);
				
				Element f1 = doc.createElement("F1");
				fuentes.appendChild(f1);
				
				Element f2 = doc.createElement("F2");
				fuentes.appendChild(f2);
				
				Element f3 = doc.createElement("F3");
				fuentes.appendChild(f3);
				
				Element f4 = doc.createElement("F4");
				fuentes.appendChild(f4);
				
				Element f5 = doc.createElement("F5");
				fuentes.appendChild(f5);
				
						
				Element propio = doc.createElement("propio");
				post.appendChild(propio);
		 
				Element tipo = doc.createElement("tipo");
				post.appendChild(tipo);
				 
			
				titulo.appendChild(doc.createTextNode(this.getTitulo().getText()));
				cuerpo.appendChild(doc.createTextNode(editor.getText()));
				tags.appendChild(doc.createTextNode(jTags.getText()));
				if (modo==0) categoria.appendChild(doc.createTextNode(Integer.toString(getCategoria())));
				System.out.println(categoriasNum[comboCat.getSelectedIndex()]);
				if (modo==2) categoria.appendChild(doc.createTextNode(Integer.toString(getCategoriaP())));
				f1.appendChild(doc.createTextNode(fInfo[0]));
				f2.appendChild(doc.createTextNode(fInfo[1]));
				f3.appendChild(doc.createTextNode(fInfo[2]));
				f4.appendChild(doc.createTextNode(fInfo[3]));
				f5.appendChild(doc.createTextNode(fInfo[4]));
				
				if (checkRecopilacion.isSelected()) propio.appendChild(doc.createTextNode("SI"));
				else propio.appendChild(doc.createTextNode("NO"));
				tipo.appendChild(doc.createTextNode(Integer.toString(modo)));
				
				
				return doc;
				
				// write the content into xml file
				
		 
			  } catch (ParserConfigurationException pce) {
				pce.printStackTrace();
			  }
		return null;
			}
	
	private JButton getReloadComu() {
		if(reloadComu == null) {
			reloadComu = new JButton();
			reloadComu.setIcon(new ImageIcon(getClass().getResource("reload.png")));
			reloadComu.setPreferredSize(new java.awt.Dimension(17, 25));
			reloadComu.setBorderPainted(false);
			reloadComu.setToolTipText("Recargar comunidades");
			reloadComu.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent evt) {
					reloadComuActionPerformed(evt);
				}
			});
		}
		return reloadComu;
	}
	
	private void reloadComuActionPerformed(ActionEvent evt) {
		config.cargarComunidades();
		rellenarComunidades();
	}
	
	

	public void eliminarPost(String postID) throws Exception {
		String contenido="";
		DataOutputStream out;
		
				
	    String line;
	    HttpURLConnection conn;
	    URL siteUrl;
	    String respuesta;
	    BufferedReader in;
		siteUrl = new URL("www.taringa.net/post.borrar.php");
		conn = (HttpURLConnection) siteUrl.openConnection();
		conn.setRequestMethod("POST");
		cook.writeCookies(conn, false);
		conn.setDoOutput(true);
		conn.setDoInput(true);
		out = new DataOutputStream(conn.getOutputStream());
		contenido="postid="+postID+"key="+key;
		System.err.println(contenido);
		out.writeBytes(contenido);
		out.flush();
		in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
		line = "";
		respuesta="";
		while((line=in.readLine())!=null)respuesta=respuesta+line; 
		System.err.println("T! me devuelve: "+HtmlEntities.decode(respuesta));
		
	}


	
	
private String procesar(String res) {

	Pattern p = Pattern.compile("[0-9]+");
	Matcher m;
	String id;
	m = p.matcher(res.subSequence(res.indexOf("url"), res.length()));
	id=m.group();
	System.err.println("Procesado. ID del post: "+id);
	return id;
	}
	
	
	
	}
	





	
